473,473 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Create a blocking and timeout client

The client program I tried to create will send some message to another
program on a different server and block wait for reply message. If
connection is timeout, close the socket.

I did something like

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

if (!socket_set_block($socket)) { // $socket is now blocking
echo socket_strerror(socket_last_error());
}

$time_soc = array("sec"=>10, "usec"=>0);
if (!socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, $time_soc))
{
die("error message is:
".socket_strerror(socket_last_error($socket))) ;
}

Is this the right way to do it? PHP fails at socket_set_option. Thanks
Jul 17 '05 #1
1 2482
Anyone has any idea?

mi****@gmail.com (Mike) wrote in message news:<8e*************************@posting.google.c om>...
The client program I tried to create will send some message to another
program on a different server and block wait for reply message. If
connection is timeout, close the socket.

I did something like

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

if (!socket_set_block($socket)) { // $socket is now blocking
echo socket_strerror(socket_last_error());
}

$time_soc = array("sec"=>10, "usec"=>0);
if (!socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, $time_soc))
{
die("error message is:
".socket_strerror(socket_last_error($socket))) ;
}

Is this the right way to do it? PHP fails at socket_set_option. Thanks

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Raja | last post by:
Hello Im trying to catch timeouts from a socket and my code looks like try: timeoutsocket.setDefaultSocketTimeout(10) s = timeoutsocket.timeoutsocket(timeoutsocket.AF_INET,...
7
by: Michi Henning | last post by:
Hi, I'm using a non-blocking connect to connect to a server. Works fine -- the server gets and accepts the connection. However, once the connection is established, I cannot retrieve either the...
11
by: Michi Henning | last post by:
Hi, I'm using a blocking Select() call on a socket with a timeout value of -1. I'd expect the call to block indefinitely, but it doesn't. When I use Poll() instead, a timeout of -1 works fine...
6
by: roger beniot | last post by:
I have a program that launches multiple threads with a ThreadStart method like the following (using System.Net.Sockets.Socket for UDP packet transfers to a server): ThreadStart pseudo code: ...
3
by: Erakis | last post by:
Hi, I have to make an ActiveX (Running on Internet Explorer) that play/record sound from soundcard. Also, I have to create a Socket to send/receive sound data to my server. I use this...
1
by: opi | last post by:
My blocking TCP server hangs in the Accept method when the client software sometimes gets an error. Are there any ways to stop this blocking in the Accept method so I dont have to restart the...
0
by: Blog the Haggis | last post by:
Hi all, I've written a program which distributes binary data to a number of clients via TCP. The program runs perfectly unless one of the client programs hangs and then it freezes while waiting...
1
by: Ryan Liu | last post by:
Hi, I have a 100 clients/ one server application, use ugly one thread pre client approach. And both side user sync I/O. I frequently see the error on server side(client side code is same, but...
5
by: Thomas Christensen | last post by:
This issue has been raised a couple of times I am sure. But I have yet to find a satisfying answer. I am reading from a subprocess and this subprocess sometimes hang, in which case a call to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.