I am new to TCP programming so here is a few simple questions:
-
Client app is calling a listener.
I am opening a connection with TcpClient:TcpClient myTcp = new TcpClient("Server", 1000); myTcp.connect();For how long will
myTcphold a connection? Is there any default value? Can I change it? -
If my calling application has a multiple threads (it’s a WCF service), each of threads has to call a listener. Can I create
myTcpas a singleton and reuse it in multiple threads? -
If question 2 yes, how many simultaneous connections can
myTcphandle? -
With singleton approach is there a chance to have synchronization issue between calls and responses?
As far as the server goes, if it’s a WCF service then WCF will take care of the threading concerns for you. You have a fair bit of control over the threading behavior of the service. But I suspect that’s not what you’re asking about.
On the client, technically you can access a TcpClient or Socket from multiple threads but you cannot read or write to it concurrently so for all intents and purposes, no don’t try to share a TcpClient across threads unless you are very familiar with synchronization locks.
But why are you using a TcpClient to talk to a WCF service? Why not use the WCF client channels to access it?