473,396 Members | 1,940 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,396 software developers and data experts.

Connection Timeout

Hi
How can i decrease the timeout on Socket.Connect??
Thanks =)
May 22 '06 #1
3 4696
This code:
s.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.SendTimeout,
1000);
would set the timeout on a send (there is similar for receive)

However it would not control the connect timeout. For that, you might need
to use a delegate with a timeout that closes the socket separately.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Kevin" wrote:
Hi
How can i decrease the timeout on Socket.Connect??
Thanks =)

May 22 '06 #2
Thanks for your reply.
But i don't under know how can i do it using a delegate, do you have an
example? =)

Thanks
"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:46**********************************@microsof t.com...
This code:
s.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.SendTimeout,
1000);
would set the timeout on a send (there is similar for receive)

However it would not control the connect timeout. For that, you might need
to use a delegate with a timeout that closes the socket separately.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Kevin" wrote:
Hi
How can i decrease the timeout on Socket.Connect??
Thanks =)

May 22 '06 #3
Here is some really clunky code that illustrates, I couldn't find the code I
eventually used, I think I used a WaitCallback or something similar. But, it
illustrates the technique:

// When the timeout for waiting for the answer is
// reached it sends a byte, causing an exception therefore terminating the
// connection.
public class TimedUdpClient : UdpClient
{
private int timeout = 1000; // 1 sec default
private Thread timeoutWatchdog;

public int Timeout
{
get { return timeout; }
set { timeout = value; }
}

public new byte[] Receive(ref IPEndPoint remote)
{
byte [] ret;
timeoutWatchdog = new Thread(new ThreadStart(StartWatchdog));
timeoutWatchdog.Start();
try
{
ret = base.Receive(ref remote);
}
catch (SocketException)
{
ret=null;
}
finally
{
timeoutWatchdog.Abort();
}
return ret;
}

private void StartWatchdog()
{

Thread.Sleep(timeout);
this.Send(new byte[] {0x00},1,"",8000);

}
}

--Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Kevin" wrote:
Thanks for your reply.
But i don't under know how can i do it using a delegate, do you have an
example? =)

Thanks
"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:46**********************************@microsof t.com...
This code:
s.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.SendTimeout,
1000);
would set the timeout on a send (there is similar for receive)

However it would not control the connect timeout. For that, you might need
to use a delegate with a timeout that closes the socket separately.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Kevin" wrote:
Hi
How can i decrease the timeout on Socket.Connect??
Thanks =)


May 22 '06 #4

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

Similar topics

2
by: Dicky Cheng | last post by:
Hi, I am using .net remoting technology. I set up a .net remoting client and server in IIS. When the client calls the server, the server will run a long duration method (30-60seconds). I have a...
3
by: kant | last post by:
stringA= "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;PWD=password;Initial Catalog=DB;Data Source=127.0.0.1;Connect Timeout=30" stringB = "Provider=Microsoft.Jet.OLEDB.4.0; Data...
6
by: Nifty | last post by:
After creating a routine to select from past ADODB connection strings, I found that it takes 60 seconds to timeout! I found the Microsoft article below ...
7
by: C# beginner | last post by:
I'm struggling with a timeout problem today. ConnectionString = "Integrated Security=true;Database=MyDatabase;Data Source=(local); Connection Timeout = 180;"; My connection string is set as...
7
by: ZRexRider | last post by:
Hi, I'm developing an application that runs on laptops that periodically connect to network. I am collecting data in local tables within the MDB. I want to recognize the occasional network...
0
by: Christopher H. Laco | last post by:
I'm in a strange situation. I have a dataset that uses it own connection string from MySettings. All is well. This thing works in .NET just dandy. If I reference this dataset from another...
3
by: Martin B | last post by:
Hallo! I'm working with C# .NET 2.0, implementing Client/Server Applications which are connecting via Network to SQL-Server or Oracle Databases. To stay independent from the underlaying Database...
6
by: michael sorens | last post by:
I have used the visual designer to create a series of DataGridViews populated from SQLServer data. A typical call is: myCountsTableAdapter.Fill(myDataSet.myCounts); My application actually...
4
by: Fred Zuckerman | last post by:
I have a A2K database that includes some linked tables (these links are SQL views). Sometimes there are "issues" with the SQL server and the users receive a timeout error whenever they try to...
7
by: =?Utf-8?B?Sm9obiBTdGFnZ3M=?= | last post by:
Hello, Please read this all before giving an answer :) I'm doing some troubleshooting on a web application that my company wrote. It's written in asp.net 1.1. The error that the Event viewer...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...
0
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...
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.