Solved

Why does our Windows service app's TCP connection keep failing with an "Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host." error?

Posted on 2015-01-05
4
535 Views
Last Modified: 2015-01-09
Hi:

I have a WCF based windows service that reads from an external device (scale) via a TCP connection.
A connection is made to the device when the service initially starts up.
This is the code we use to initiate the connection to the device:
scaleData.Client = New TcpClient(ipAddress, (portNumber))
scaleData.Stream = scaleData.Client.GetStream()

Open in new window

The service is hosted as a Windows service (as opposed to through IIS).

We have two applications that pull data from the WCF service,
an asp.net application and a winforms application.

The request returns data from the stream to the caller/client.
 Try
                    Dim bytes As Int32 = scaleData.Stream.Read(data, 0, data.Length)
                    responseData = Text.Encoding.ASCII.GetString(data, 0, bytes)c
 Catch ex As IOException
                    exceptionMsg = String.Format("IOEXCEPTION!!! :: {0}", ex.Message)
End Try

Open in new window


Both the (winforms) test application, web application and windows service all reside on the same Windows 7 machine.

For the most part, this configuration works fine. But occasionally it fails.(we can't quite determine the pattern to it or specifics to it's occurrence) with the following message:
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host

Open in new window

Upon failure, we now added retry logic to try to reestablish the TCP connection and read from the stream,
but that doesn't seem to fix the issue. I've also got logging enabled which captures the exceptions to a log file. All the log shows is the above mentioned message.

Does anyone have any suggestions as to what is going on here?
Is this a Firewall/Port/virus scanner issue?

How do we best proceed?

Thanks,
JohnB
0
Comment
Question by:jxbma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 28

Expert Comment

by:Dan McFadden
ID: 40533092
Since you're using Win7 to host the service (as opposed to a server OS), I am curious to how many tcp connections you are opening to the endpoint.  Win7 has a connection limit of 20.  If you were to try to establish a 21st connection, the service host would deny the connection.

As a suggestion, I would try to track the number of connections to the service endpoint to see if you occasionally exceed 20.  A quick way to watch active connections (in and out) is to download TCPView from Sysinternals.  It will display open udp/tcp connection details including origin, destination and a few other interesting tid-bits of info.

Another thought, are you establishing the connection via IP address to port 80/tcp (based on reference to IIS), if you have a proxy on your network that manages connections, it could also be a source of connection problems.

Dan
0
 
LVL 28

Accepted Solution

by:
Dan McFadden earned 250 total points
ID: 40533097
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 250 total points
ID: 40533164
Well, the error indicates that it is the remote device that is dropping the connection.  Perhaps it is disconnecting after a period of inactivity on the connection.

You starting point should probably be the supplier/documentation for the device you're connecting to.
0
 
LVL 1

Author Closing Comment

by:jxbma
ID: 40540434
Ultimately, since we are trying to read to the device on demand, I reestablish the TCP connection on every request.
This seems to work for now (until I see another better solution).

Thanks for the responses,
JB
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question