473,486 Members | 2,401 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Socket timeout

Hi

I'm working with sockets and I'm curious about the timout when trying to
connect to a server on a specific port.

My code looks like this:

Socket client = new
Socket(AddressFamily.InterNetwork,SocketType.Strea m,ProtocolType.Tcp);
int port = Int32.Parse( TextBox_Port.Text );
string ip = TextBox_IP.Text;
ipAdd = IPAddress.Parse( ip );
remoteEP = new IPEndPoint ( ipAdd, port );
client.Connect (remoteEP);

What I can't get a grip on is the long timout period if the server does not
respond.

I've tried adding:

client.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.SendTimeout, 500);
client.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.SendTimeout, 500);

but this does not help...

Is there a way of controling the timeout on connect?

/Johan
Nov 17 '05 #1
2 6890

Did you try setting ReceiveTimeout also?

David.
"Johan" wrote:
Hi

I'm working with sockets and I'm curious about the timout when trying to
connect to a server on a specific port.

My code looks like this:

Socket client = new
Socket(AddressFamily.InterNetwork,SocketType.Strea m,ProtocolType.Tcp);
int port = Int32.Parse( TextBox_Port.Text );
string ip = TextBox_IP.Text;
ipAdd = IPAddress.Parse( ip );
remoteEP = new IPEndPoint ( ipAdd, port );
client.Connect (remoteEP);

What I can't get a grip on is the long timout period if the server does not
respond.

I've tried adding:

client.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.SendTimeout, 500);
client.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.SendTimeout, 500);

but this does not help...

Is there a way of controling the timeout on connect?

/Johan

Nov 17 '05 #2
Sorry, of course the second "client.SetSocketOption" stated ReceiveTimeout,
I just made a typo.
None of these work...

Johan.
"David Hoerster" <Da***********@discussions.microsoft.com> wrote in message
news:E2**********************************@microsof t.com...

Did you try setting ReceiveTimeout also?

David.
"Johan" wrote:
Hi

I'm working with sockets and I'm curious about the timout when trying to
connect to a server on a specific port.

My code looks like this:

Socket client = new
Socket(AddressFamily.InterNetwork,SocketType.Strea m,ProtocolType.Tcp);
int port = Int32.Parse( TextBox_Port.Text );
string ip = TextBox_IP.Text;
ipAdd = IPAddress.Parse( ip );
remoteEP = new IPEndPoint ( ipAdd, port );
client.Connect (remoteEP);

What I can't get a grip on is the long timout period if the server does
not
respond.

I've tried adding:

client.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.SendTimeout, 500);
client.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.SendTimeout, 500);

but this does not help...

Is there a way of controling the timeout on connect?

/Johan

Nov 17 '05 #3

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

Similar topics

17
52103
by: Achim Domma | last post by:
Hi, I'm using Python 2.3s timeout sockets and have code like this to read a page from web: request = ... self.page = urllib2.urlopen(request) and later:
3
2639
by: Thomas Hervé | last post by:
My problem is not really python specific but as I do my implementation in python I hope someone here can help me. I have two programs that talk through a socket. Here is the code : <server>...
5
4204
by: Russell Warren | last post by:
Does anyone know the scope of the socket.setdefaulttimeout call? Is it a cross-process/system setting or does it stay local in the application in which it is called? I've been testing this and...
3
4611
by: Robert A. van Ginkel | last post by:
Hello Fellow Developer, I use the System.Net.Sockets to send/receive data (no tcpclient/tcplistener), I made a receivethread in my wrapper, the receivethread loops/sleeps while waiting for data...
4
18084
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed...
2
15298
by: djc | last post by:
I read a network programming book (based on framework 1.1) which indicated that you should 'never' use the RecieveTimeout or the SendTimeout 'socket options' on TCP sockets or you may loose data. I...
1
4423
by: jnair | last post by:
When using socket.socket.settimeout we normally only guard against "socket.timeout" exception.Now the implementation of "settimeout" in "Python-2.4.3/Modules/socketmodule.c" sets the socket fd to...
2
2790
by: Robin Becker | last post by:
While messing about with some deliberate socket timeout code I got an unexpected timeout after 20 seconds when my code was doing socket.setdefaulttimeout(120). Closer inspection revealed that...
2
10654
by: carl.rosenberger | last post by:
Hi, I am trying to get the following behaviour for my Socket connection: (1) Attempt a blocked read for a defined amount of time. (2) If a timeout occurs, because no data has been sent to the...
2
3519
by: Heikki Toivonen | last post by:
M2Crypto has some old code that gets and sets socket timeouts in http://svn.osafoundation.org/m2crypto/trunk/M2Crypto/SSL/Connection.py, for example: def get_socket_read_timeout(self): return...
0
6967
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
7180
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6846
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
7341
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
4564
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
600
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
266
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.