A
Abhishek
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
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