Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
First,i am from china,my english is pool.hehe!
Here is the code:
C#
socketControl = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
           IPEndPoint ep = new IPEndPoint(IPAddress.Parse(RemoteHost), strRemotePort);

           // 链接
           try
           {
               socketControl.Connect(ep);

           }
           catch (Exception)
           {
               throw new IOException("Couldn't connect to remote server");
           }

at the begin socketControl is success connected,but soon after connection time out , How to set the connection time?
Posted

check the instance properties Socket.SendTimeout and Socket.ReceiveTimeout where 0 and -1 mean infinite
 
Share this answer
 
You can't set a connection time out value from the client side, usually connection time outs or idle time limits are controlled from the server side where the server keeps track of the idle times for the connections and forces close those that exceed the limits. One way to avoid this is by setting the KeepAlive[^] SocketOption.

Now from the code you posted, IF you are getting the IOException that you have defined then your connection is actually failing and you need to look at the actual exception that is occurring and not throwing a custom one.

The only time out limits that you can set from the client side are for sending and receiving data.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900