[Sussex] Socket problem - Fedora core 3

Brendan Whelan b_whelan at mistral.co.uk
Tue Sep 27 10:58:54 UTC 2005


Hello,

I have a sockets routine, in PHP, for sending messages to another system. It sends and receives responses but I am trying to make the program more robust by timing out the read from the other system. If I get a timeout I will assume that the message hasn't been receive and send it again. I have tried various methods without success.

My original code connects as follows (I have stripped out all the error checking code, etc):

$sock = socket_create(AF_INET, SOCK_STREAM, 0);

$return = socket_bind($sock, $system_ip, $port);

$client = socket_listen($sock);

$conn = @socket_accept($sock)

stream_set_timeout($conn, $timeout);

Warning: stream_set_timeout(): supplied argument is not a valid stream resource
I close the program before exiting the program
------------------------------------------------

I then tried to get a valid stream by using fsockopen:

$sock = fsockopen($system_ip, $port, &$errno, &$errstr, $timeout);

But I get a failure to connect:

Warning: fsockopen(): unable to connect to xxx.xxx.xxx.xxx:21235
Error 111 - connection refused.

Any suggestions?

Thanks, Brendan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.lug.org.uk/pipermail/sussex/attachments/20050927/31d09929/attachment.htm 


More information about the Sussex mailing list