Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
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
Medium Priority
?
633 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 29

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 29

Accepted Solution

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

Assisted Solution

by:Carl Tawn
Carl Tawn earned 1000 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

Simple, centralized multimedia control

Watch and learn to see how ATEN provided an easy and effective way for three jointly-owned pubs to control the 60 televisions located across their three venues utilizing the ATEN Control System, Modular Matrix Switch and HDBaseT extenders.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

647 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