473,398 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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 6882

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
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
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
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
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.