Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Client Server application: The client requests a connection the Server accepts the connection.

After establishing the connection we can send data.

Problem: when the communication link of the client and server is lost then the client fails to connect to the server as its e.request ID is different and the server has already accepted the previous ID.

In my application i want that, On finding the lost link the client and server should maintain the connected status and the data transmission should not stop.

Kindly help.
Posted
Updated 31-Aug-13 2:21am
v2
Comments
pdoxtader 31-Aug-13 8:39am    
You need to build that kind of resilience in yourself... No one is going to do it for you, and I'm fairly sure there isn't a block of code someone can just drop in here, and your problem is solved.

You have to catch the disconnects, and reconnect, and then handle the resumption of your data transfer yourself... and it may NOT be possible "maintain the connected status". One of the computers may have been unplugged, or disconnected from the network. You have to handle that too.

You just need to spend the time and build this.

- Pete
Sergey Alexandrovich Kryukov 31-Aug-13 12:15pm    
Exactly. I provided some suggestions in my answer, please see.
—SA
Sergey Alexandrovich Kryukov 31-Aug-13 12:00pm    
This is not how things work. You should develop the concept of client identification independent from TCP session.
—SA

1 solution

First of all, with .NET, sockets are not exactly WINSOCK. Sockets are implemented in the way abstracted from OS and OS-specific APIs. That's why CLR on different OS is possible. In particular, Mono is the different implementation of CLR available on Windows and a number of other OS. For .NET, sockets API is presented via the class System.Net.Sockets.Socket, or, on a bit higher level and for TCP only (highly recommended in most cases), via the pair of classes: System.Net.Sockets.TcpListener and System.Net.Sockets.TcpClient:
http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.aspx[^],
http://msdn.microsoft.com/en-us/library/system.net.sockets.tcplistener.aspx[^],
http://msdn.microsoft.com/en-us/library/system.net.sockets.tcpclient.aspx[^].

Now, about your problem. First of all, the problem is not 100% fully formulated, as we don't know what exactly you mean by "ID". Not to worry.

Please see the comments to your question. Of course, you cannot talk about "maintaining connected status" as from the very beginning you are assuming the possibility of physical disconnection. You can develop some "logical" connection which carries the semantic of the connection between the client and server (listener) part. For example, you can develop a concept of persistent client identification. You may have a mechanism of issuing and supporting of the unique client ID, but persistent one. For example, your server can provide the API for issuing of the unique ID on request. The scope of uniqueness should be just the server process, so it does not have to be world-unique (as many try to achieve using GUIDs, which would be pointless; some integer identifier would be good enough. The client can request and store the ID on client side. In case of disconnection, the client should submit stored ID instead of requesting a new one, and the server side would be able to locate the data relevant to the client using this ID. Something like that.

See also my two past answers, which are not quite relevant to your problem, but may give you some ideas:
an amateur question in socket programming[^],
Multple clients from same port Number[^].

—SA
 
Share this answer
 
v2

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