Re: Help getting a socket to work?
From: Martin (martinvalley_at_comcast.net)
Date: 09/03/04
- Next message: MRe: "PHP memory management"
- Previous message: Andrew DeFaria: "Re: PHP debugging"
- In reply to: Daniel Tryba: "Re: Help getting a socket to work?"
- Next in thread: Daniel Tryba: "Re: Help getting a socket to work?"
- Reply: Daniel Tryba: "Re: Help getting a socket to work?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 02 Sep 2004 17:30:50 -0700
Andy / Daniel -
Thanks.
>Mayeb you found another program that is broken by SP2 :)
yeah, very well could be.
>
>> echo "Reading response: <br><br>";
>> while ($out = socket_read($socket, 999, PHP_NORMAL_READ)) {
>> echo $out;
>> }
>
>
>This blocks untill:
>- 999 bytes are read.
>- a \n, \r or \0 is received
>
>Are these conditions met?
No, they weren't. I didn't know I needed to do that. When I added \n
to the message from the server, the script started working all the way
through. However, I'm still getting an error on the socket_read. It
says: "unable to read from socket. operation completed successfully."
I tried taking the socket_read out of the "while" construct but it
didn't make any difference.
I found a comment on the PHP.net site that said that socket_read
doesn't work in Windows (the comment is nearly a year old). The writer
says to use: socket_recv instead. I tried it thus:
$rcd=socket_recv($socket,$buffer,999,0);
echo $rcd;
echo "<br>" . $buffer;
It worked!
Howeer, this appears to NOT wait on any terminating character. Since
it's possible for tcp/ip to break up the messages, I'm concerned that
I'll always receive complete messages. (I've had problems with that in
the past).
>BTW why socket_* and not fsockopen?
Because I don't know any better. Should I be using it?
Any other advice and guidance will be greatly appreciated.
Thanks again.
- Next message: MRe: "PHP memory management"
- Previous message: Andrew DeFaria: "Re: PHP debugging"
- In reply to: Daniel Tryba: "Re: Help getting a socket to work?"
- Next in thread: Daniel Tryba: "Re: Help getting a socket to work?"
- Reply: Daniel Tryba: "Re: Help getting a socket to work?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|