Re: A question about UDP packet receive



Reeze <reeze.xia@xxxxxxxxx> wrote:

I need your help!
I created a UDP server by using $socket =
stream_socket_server($udpAddr, $errno, $errstr, STREAM_SERVER_BIND);
the client send me a reqest, then server return a "hello string".
but the client simply send me a name or something very short. I have
to read upto 100 chars, then the fread can return.

my Question is: how can I read a udp packet which length is unknow?
...
my src code:=====================================
$pkt = stream_socket_recvfrom($socket, 100, 0, $peer);

$reciv_data = fread($socket, 100);
$message = preg_replace("/[[:space:]]/", '', $reciv_data); // cleanup
data
$response = "hello, $message";
stream_socket_sendto($socket, $response, 0, $peer);

echo " In > [$message] \n";
echo " Out > [$response] \n";

I suggest that you use EITHER stream_socket_recvfrom OR fread. Both serve
the same purpose in this case, but fread adds another level of buffering.
It doesn't sound like you really want the buffering.
--
Tim Roberts, timr@xxxxxxxxx
Providenza & Boekelheide, Inc.
.



Relevant Pages

  • UDP Broadcast issues.
    ... I am trying to write a UDP Server and Client. ... but I don't ever seem to receive the broadcast messages on the ... // Create the socket, and attempt to connect to the server ...
    (microsoft.public.win32.programmer.networks)
  • Re: Best method for an NT service and python to interact?
    ... unsuspecting patrons the following literary masterpiece: ... the client does it and the NT service can stay very ... Setting up a simple UDP server is a great idea and I ...
    (comp.lang.python)
  • A question about UDP packet receive
    ... I created a UDP server by using $socket = ... the client send me a reqest, then server return a "hello string". ...
    (comp.lang.php)
  • Re: Select/Poll
    ... A UDP server or client cannot just send 100 messages in one shot and ... You can check that they get to the wire in all cases by watching ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)