Ok here is the story :
I got a php script that comunicates with a game server (Half-life). This
script uses socket_set_timeout.
But the build of php i downloaded doesn't support socket_set_timeout().
So i started to modify the script to do without.
Here is the prob : the script use the socket as blockant. But without
socket_set_timeout it could be a problem.So i try with a non-blockant socket
but i don't get any response from the game server.
Here is a portion of the code :

  if (!$cssocket=fsockopen("udp://".$serveraddress,$portnumber,$errnr)) {
   $this->errmsg="No connection";
   return "";
  }

  socket_set_blocking($cssocket,false);
  fwrite($cssocket,$command,strlen($command));

//  sleep(1);
  do {
   $data=fread($cssocket,1024);
   $serverdata.=$data;
   $serverdatalen=strlen($serverdata);
   $socketstatus=socket_get_status($cssocket);
//  } while ($socketstatus["unread_bytes"] );
  } while (time()-$starttime<5 );

The main prob is that : in blockant mode it works fine. In non-blockant mode
i don't receive anything. But if i do a sleep(1) before the first read (the
commented line) then it works..

Another way of the problem :
loop {
            readdata from socket;
            append to data akready read;
} while moredata or not_timed_out

In blockant mode it works.
In non-blockant mode i never receive something !! WHY ??

I understand why it works in blockant mode : the read function waits untill
the has arrived.
But in non-blockant the read function should return the data already arrived
then return.
And the second time i launch it, it should give me the data that arrived
since the last time.

I think i missed something, but i cannot see what.

Please help me.

Sorry about my English, it's not my main language... :)

See you later





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to