Continuously running socket connection
Posted: Thu Feb 05, 2004 10:28 am
I have a server that is going to have a continuous socket connection on linux. Is there a way with php to send information to that socket? I currently have code to open a socket send information, receive a response, and then close the socket. However this socket is going to be open already and I need to be able to send data to it and retrieve data from it.
Here is what I currently have.
$host = "100.100.100.100";
$port = 21572;
//Open a client connection
$fp = fsockopen($host, $port, $errno, $errstr);
if (!$fp){
$result = "Error: Could not open socket connection";
}else{
//Write the user string to the socket
fputs ($fp, $output, strlen($output));
socket_set_timeout($fp, 30);
//Get Respones
//Get first five bytes to determine full size
$result = fread($fp, 5);
$bytes_left = socket_get_status($fp);
//Get the remaining results with known byte size
$result .= fread($fp, $bytes_left["unread_bytes"]);
//close the connection
fclose($fp);
}
This currenly works, but the server I am contacting would like me to have the socket open at all times. Therefore I need to send data to the already open socket.
Thanks in advance,
Here is what I currently have.
$host = "100.100.100.100";
$port = 21572;
//Open a client connection
$fp = fsockopen($host, $port, $errno, $errstr);
if (!$fp){
$result = "Error: Could not open socket connection";
}else{
//Write the user string to the socket
fputs ($fp, $output, strlen($output));
socket_set_timeout($fp, 30);
//Get Respones
//Get first five bytes to determine full size
$result = fread($fp, 5);
$bytes_left = socket_get_status($fp);
//Get the remaining results with known byte size
$result .= fread($fp, $bytes_left["unread_bytes"]);
//close the connection
fclose($fp);
}
This currenly works, but the server I am contacting would like me to have the socket open at all times. Therefore I need to send data to the already open socket.
Thanks in advance,