vishank Posted May 12, 2009 Share Posted May 12, 2009 Hi there, I am new to PHP and facing some issue while trying to connect my flash application with XMLSocket server. Actually i picked some code (thnx to google) and using it. Its working perfectly and my difference instances of flash are able to communicate to each other. But everytime some data is passed from XMLSocket server to my flash application, it says "Resource id #[some number]" where i want it to be some name. So the question is, how to enable such kind of functionality where i can get the users name instead of getting "Resource id #[some number]" message. Below is the php code i am using. Hope it will help somewhere: #!/usr/bin/php -q <?php error_reporting(E_ALL); set_time_limit(0); ob_implicit_flush(); $address = 'xxx.xxx.xxx.xxx'; $port = 9999; function send_Message($allclient, $socket, $buf) { foreach($allclient as $client) { socket_write($client, "$socket wrote: $buf"); } } if (($master = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0) { echo "socket_create() failed, reason: " . socket_strerror($master) . "\n"; } socket_set_option($master, SOL_SOCKET,SO_REUSEADDR, 1); if (($ret = socket_bind($master, $address, $port)) < 0) { echo "socket_bind() failed, reason: " . socket_strerror($ret) . "\n"; } if (($ret = socket_listen($master, 5)) < 0) { echo "socket_listen() failed, reason: " . socket_strerror($ret) . "\n"; } $read_sockets = array($master); while (true) { $changed_sockets = $read_sockets; $num_changed_sockets = socket_select($changed_sockets, $write = NULL, $except = NULL, NULL); foreach($changed_sockets as $socket) { if ($socket == $master) { if (($client = socket_accept($master)) < 0) { echo "socket_accept() failed: reason: " . socket_strerror($msgsock) . "\n"; continue; } else { array_push($read_sockets, $client); } } else { $bytes = socket_recv($socket, $buffer, 2048, 0); if ($bytes == 0) { $index = array_search($socket, $read_sockets); unset($read_sockets[$index]); socket_close($socket); }else{ $allclients = $read_sockets; array_shift($allclients); send_Message($allclients, $socket, $buffer); } } } } ?> Hope to hear from you soon. Link to comment https://forums.phpfreaks.com/topic/157779-how-to-get-clients-name-xmlsocket-server/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.