Hi I have written a Socket Client program to connect to a Socket based server system running on Java.
I am able to connect to the host system using their IP and Port. I got the response message back from the host. This client program is running on our production system for more than three months. The problem I am facing now is for some reasons some of my message are hanging at the host system and the host never return a message, which makes my Socket Client to wait for the response for indefinite time. So now I need to disconnect from the host if it takes more than 30 seconds. I did some research to implement the timeout in my client program but I did find anything which will solve my problem. Here is the code for my client program ===================================== Socket m_socClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); String szIPSelected = "000.000.000.000"; String szPort = "2000"; int alPort = System.Convert.ToInt16(szPort,10); System.Net.IPAddress remoteIPAddress = System.Net.IPAddress.Parse (szIPSelected); System.Net.IPEndPoint remoteEndPoint = new System.Net.IPEndPoint (remoteIPAddress, alPort); m_socClient.Connect(remoteEndPoint); strMsg = "test msg"; byte[] byData = System.Text.Encoding.ASCII.GetBytes(strMsg); m_socClient.Send(byData); byte [] buffer = new byte[1024]; int iRx = m_socClient.Receive (buffer); char[] chars = new char[iRx]; System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder(); int charLen = d.GetChars(buffer, 0, iRx, chars, 0); System.String szData1 = new System.String(chars); msResponseMsg = szData1; ========================================== I would appreciate your inputs on how to implement timeout to force the client to disconnect from the server. thanks Raj =================================== This list is hosted by DevelopMentor� http://www.develop.com NEW! ASP.NET courses you may be interested in: 2 Days of ASP.NET, 29 Sept 2003, in Redmond http://www.develop.com/courses/2daspdotnet Guerrilla ASP.NET, 13 Oct 2003, in Boston http://www.develop.com/courses/gaspdotnet View archives and manage your subscription(s) at http://discuss.develop.com
