How to create / simulate a persistent TCP connection?

It seems that WCF TCP connections are not persistent. The first ping answer takes some time, but subsequent processes take less time. After a while, it takes a lot of time - another reconnection?

SERVER> Starts with net.tcp: //0.0.0.0: 999

CLIENT> Connection created in net.tcp: // localhost: 999 // Not a real connection, ready to connect

CLIENT> Reply to Ping in 1s163ms // First connection

CLIENT> Response to Ping in 22 ms // Already connected

CLIENT> Reply to ping in 26 ms

CLIENT> Ping Response in 24 ms

CLIENT> 325 ms Ping Response // Reconnected

CLIENT> Response to Ping in 19 ms

CLIENT> Response to ping in 767 ms // Reconnect

If true, what is the downtime value for a tcp connection before it is disconnected? I need to stay connected online.

Update Modified Code:

NetTcpBinding tcpBind = new NetTcpBinding(); tcpBind.ReliableSession.Enabled = true; tcpBind.ReliableSession.Ordered = true; tcpBind.ReliableSession.InactivityTimeout = TimeSpan.FromMinutes(10); ServiceHost svh = new ServiceHost(typeof(ServiceImplementation)); svh.AddServiceEndpoint( typeof(WCFSimple.Contract.IService), //new NetTcpBinding(), tcpBind, String.Format("net.tcp://{0}:{1}", ip, port)); svh.Open(); 

Now I got another error:

The http://tempuri.org/IService/Pong action is not supported by this endpoint. Only WS-ReliableMessaging February 2005 messages are processed by this endpoint.

Update I changed only the server side and caused an error. Then I modified TCP on the client side as reliable messaging.

+6
source share
2 answers

I do not think Ping is a good tool for testing a TCP connection. Because Ping uses ICMP as its main protocol instead of TCP.

I suggest you create a WCF client, connect to the service, and then test the TCP connection using some network downgrade tools or just use netstat for a quick check.

+1
source

Typically, WCF connections are temporary, although there are several connection pools in the background.

Using net.tcp as a transport, permanent (long-term) connections are possible. The code you posted is one way to achieve this.

For more information and some alternatives, check out What You Need to Know About One-Way Calls, Callbacks, and Events , an MSDN journal article from October 2006.

Also used are IsInitiating and IsTerminating , available in the OperationContract attribute.

+1
source

Source: https://habr.com/ru/post/894989/


All Articles