Okay here is what I've got
I have a pretty decent socket server that can take multiple connections and buffer thigns to the appropriate client (although my code just talks back to the client at the moement that submitted thereqeust)
I'm a little lost to be honest in how the actual communication is being handled and who is doing what. Here is my server called from CLI onlinux
$address = '127.0.0.1';
$port = 7503;
function onChange ($clients, $socket, $input, $bytes)
{
foreach($clients as $client)
{
if (trim($input) == "exit")
{
socket_close($client);
//socket_shutdown($sock);
exit();
}
else
{
//echo "user ".$client." says ".trim($input)."<br>";
socket_write($client, "<script>window.parent.add('".$client." says ".trim($input)."');</script>");
//flush();
}
}
}
// Create a TCP Stream socket
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
// Bind the socket to an address/port
socket_set_option($sock, SOL_SOCKET, SO_REUSEADDR, 1);
socket_bind($sock, $address, $port) or die('Could not bind to address');
// Start listening for connections
$listen = socket_listen($sock, 5);
//socket_set_nonblock($sock);
$all_listen=array($sock);
while(true)
{
$changed_sockets = $all_listen;
$num_changed_sockets = socket_select($changed_sockets, $write = NULL, $except = NULL, NULL);
foreach($changed_sockets as $socket)
{
if ($socket == $sock)
{
if ($client = socket_accept($sock)) array_push($all_listen, $client);
else echo $socket." cannot connect";
}
else
{
$bytes = socket_recv($socket, $buffer, 2048, 0);
if ($bytes == 0)
{
$index = array_search($socket, $all_listen);
unset($all_listen[$index]);
socket_close($socket);
}
else
{
$ALL = $all_listen;
array_shift($ALL);
onChange($ALL, $socket, $buffer, $bytes);
}
}
}
}
here is my listener on the site
$host="127.0.0.1";
$port = 7503;
/* works but ends connection */
$sock = socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp'));
//socket_set_option($sock, SOL_SOCKET, SO_REUSEADDR, 1);
socket_connect($sock, $host, $port);
socket_set_option($sock, SOL_SOCKET, SO_BROADCAST,2050);
while(true)
{
$recieve = socket_read($sock, 1024);
echo $recieve;
}
socket_close($sock);
its doing well for the client to get is own feedback back
I'm going to USE APC to assing users to socket resources and distrubte the messages however the browser isnt getting back any information from the client.
I'm hoping to get some help because although its working 50% there i'm still a bit confused in the proccess and therefore have trouble troubleshooting
Any Suggestions
EDIT::: HAHAHA
Nevermind I forgot to flush, dir