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
492 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

730 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