Log in

View Full Version : client server interaction



sukanya.paul
05-09-2008, 03:45 AM
hi,
I have been given an assignment where I need to create a basic chat window application using only PHP between two systems , one acting as server and other as client . I need to know how to connect the client machine to server machine using IP, Port number and sockets.
i need to do this at the earliest,but don't have a clue.
Can someone please help.
thanks in advance..
suk

TimFA
05-09-2008, 05:26 AM
One: if this is an assignment, I don't think I should do it for you. Two: I wasn't aware that PHP could do that...I thought it would need help from Ajax/Flash. Anyways, someone who does know how to do that (if its possbile) will be along sometime to help you out. Good luck.

Tim

sukanya.paul
05-09-2008, 05:28 AM
i was not asking any1 to do it for me.. what i was asking was for a guideline..
thanks anyways

sukanya.paul
05-09-2008, 05:29 AM
and it is possible... just getting some errors.. and if you don't know anything abt it..den ur reply was meaningless...

TimFA
05-09-2008, 04:04 PM
Yes, it was. I figured you'd like to know atleast someone read and tried. Some people get impatient.

thetestingsite
05-09-2008, 05:07 PM
it is possible... just getting some errors..

Post the code you have so far and the errors that you are getting.

phpsales
05-10-2008, 01:39 PM
The easiest method for PHP chat is via HTTP (port 80). However, if you are required to use sockets you would want to use the PHP fsockopen() module (php.net/fsockopen). This module will allow you to open a socket connection for both reading/writing. It also allows you to manage the resource connection as if you where working with a file (thank you PHP). Meaning you can use the PHP file modules to work with the socket connection, fread(), fwrite(), etc...


resource fsockopen ( string $hostname [, int $port [, int &$errno [, string &$errstr [, float $timeout ]]]] )

Example #1 fsockopen() Example (php.net/fsockopen)


<?php
$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: www.example.com\r\n";
$out .= "Connection: Close\r\n\r\n";

fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
?>