I have a Client & Server c# program.
The Client ( the one who’s receiving connections).
The server ( is the one who’s connecting to the client ).
When the server is opened the customer(server)with his email and address appears in the Client window.
BUT when the client is closed and reopened then connection is loosed and the customer needs to close the server and open it again.
How can I maintain the connection without telling the customer to close and reopen the server?
I’m using TCP Connection and scokets.
A solution for this might be using lazy connection initialization with error handling for cases when the “client” is not online.
You can create a wrapper for your connection, which handles the initialization, can check current connection state and wrap all your actions with error handling in case the connection could not be initialized.
WCF is a good abstraction layer for this, but might be too heavyweight and has quite steep learning curve, especially its setup/config part in your project.
Also, as was already mentioned, it is part of the client/server design that usually the client initializes the communication with some sort of login/subscription message, not the other way around – that would solve your problem here as well.