HI Niel and thanks for your answer...i will look into it. Maybe it's a stupid question but can't i read one packet at a time and put i into it's own variable? or is it just a stream of data that stops when there is no more data to send ?
(I better go read something about UDP packets 8) ) I hope this understand what i am saying. "Neil Smith" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Since you are getting some data back from the server when connecting in this manner, everything seems to be okay. However - remember that UDP is a connectionless protocol (unlike TCP which has a form of packet accounting), you may not *necessarily* get all the packets delivered which may impact finding an EOF sequence. You may need to set a socket timeout value (use socket_set_timeout() or stream_set_timeout() with something reasonable, say 1 second) which continues the script if no more data is being received. Read more about this here : http://www.php.net/manual/en/function.fsockopen.php and http://www.php.net/manual/en/function.socket-set-timeout.php I have also verified that some versions of PHP (<4.2) will hang up a script (up to the script timeout) if a packet request is blocked by a firewall on the other end. You can read more about this in a bug report submitted in February. http://bugs.php.net/bug.php?id=15639 Hope it works out. Regards, Neil Smith. At 08:04 02/01/2003 +0000, you wrote: >Message-ID: <[EMAIL PROTECTED]> >To: [EMAIL PROTECTED] >Reply-To: "Torben Dehn" <[EMAIL PROTECTED]> >From: "Torben Dehn" <[EMAIL PROTECTED]> >Date: Wed, 1 Jan 2003 17:34:05 +0100 >Subject: UDP packet > >Hello ! > >I am very new to PHP so please don't laugh if my code really sucks ;=) > >What i am trying to do is : > >1) Opening an UDP connectión to a server (That works allright) >2) Making a query to the server (That works allright) >3) Recieve an unknow number of UDP packets with an unknown packet size (This >is my problem) > >I don't know the packet size and i don't know how many packets the server >will return... >Take a look at the WHILE loop because thats where it "hangs". >If i remove the WHILE loop and just make a fread($socket,1024) it will >return some data. > >My questions are as follow : >1) How can i make sure that ALL data has been recieved ? >2) Is it possible to read each UDP packet into it's own variable (array) ??? > >I would be very happy if someone could answer one or all question. > > ><? >$ip = "192.246.40.65"; >$port = 27950; >$command = "˙˙˙˙getservers 60 empty full"; >$data = ''; > >Echo "Connecting to Master Server : $ip:$port<br>"; >$socket = fsockopen("udp://$ip",$port,$errno,$errstr,2); >if (!$socket) > { > echo "There was an error connecting to the Master Server<br>"; > echo "Error returned was : $errorno and $errostr"; > exit; > } //Socket error > else > { > echo "Connection established ..<br>"; > If (!fwrite($socket,$command)) > { > echo "There was an error querying the master server .."; > exit; > } //Fwrite error > echo "Query complete ..<br>"; > >while (!feof($socket)) > { > echo "Reading data ..<br>"; > $data .= fread($socket,4096); > } //End of read section > > echo "$data<br>"; > > fclose($socket); > echo "Connection closed ..<br>"; > } //End of main loop > >?> -- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php