PC Review


Reply
Thread Tools Rate Thread

C# .NET server Socket class And VB Client Winsock API(Problem Recognising disconnection)

 
 
Abhishek
Guest
Posts: n/a
 
      26th Jun 2004
Hello All,

I am using C#.NET Socket Class At server And Winsock API at Visual
Basic Client.Every thing is working well.

I want to give facility of reconnecting to client if connection
terminates due to any problem either from server connection or from
client connection and resume it from its old state.

The code I am using for it is as follows:


TcpListener listener = new TcpListener(1001);
listener.Start();

socket =listener.AcceptSocket();

Above socket object is communicating with client.

To check if connection is alive i have wrote following code.
noOfTry=0;
while(noOfTry<5)
{
try
{
this.socket=this.getSocket();

this.socket.Send(byteData,0,noOfBytes,System.Net.Sockets.SocketFlags.None);
break;
}
catch(SocketException ex)
{
noOfTry++;
Thread.Sleep(2000*noOfTry);
this.socket=this.getSocket();
}
}


Problem I am facing is that socket is not throwing SocketException if
connection has broken and executes socket.send() method without any
exception. However when second time this method is called it throws
SocketException

I am using socket.receive() method to receive data in blocking state.
If client has closed itself normally, socket.receive() method at
Server side detects connection broken by receiving Zero bytes. But if
there is some problem in network, then socket.receive()method also
fails to detects it and thread is blocked for ever in
socket.receive().

Please suggest me what to do?????
Any suggestion or Code will be appericiated.....

Thanks n Regards,

Abhishek Agarwal
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Socket] detecting the (brute) disconnection of a client timor.super@gmail.com Microsoft C# .NET 9 4th Apr 2007 05:21 PM
acynchronous client and server problem using socket =?Utf-8?B?d3VrdW4=?= Microsoft Dot NET Framework 0 22nd Feb 2006 07:20 AM
Socket Server to Socket Client..Client function not working when called from Server... trint Microsoft C# .NET 2 13th Apr 2005 09:43 PM
Asynchronous Socket Client class problem =?Utf-8?B?TWF0dGhldyBLaW5n?= Microsoft C# .NET 3 18th Feb 2004 04:20 PM
client/server socket problem Paul Fi Microsoft C# .NET 1 17th Feb 2004 03:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:44 AM.