473,714 Members | 2,365 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Receive Error: Unable to Read Data From The Transport Connection

I'm trying to create a small messenger program that uses the tcpclient and
tcplistenter objects. When I start the application and run the thread that
fires the tcplistener; once the client sends data then closes the stream and
the connection I receive the message Unable to read data from the transport
connection: An existing connection was forcibly closed by the remote host.
How can I keep the connection listener listening for new traffic?

Here is the code I have:

---------Button Click Event-----------------------------------
Dim t1 As New Thread(AddressO f StartListening)
If btnStartListeni ng.Text = "Start Listening" Then
t1.Name = "ListenThre ad"
t1.IsBackground = True
t1.Start()
ElseIf btnStartListeni ng.Text = "Stop Listening" Then
t1.Abort()
StopListening()
Dim server As TcpListener
server = Nothing
------------------------------------------------------------------------
Private Sub StartListening( )
Try

server = New TcpListener(ipL ocalEndPoint)
server.Start() 'Start listening for client request.
Dim showProgress As New ChangeFormStatu s(AddressOf ChangeStatus)
'Inform user that the app is now listening.

Me.Invoke(showP rogress, status.ONLINE)

Dim client As TcpClient
Dim Bufferbytes(102 4) As Byte 'Buffer for reading data.
Dim incomingMessage As String = Nothing 'Variable for incoming
message
Dim showMessage As New DisplayText(Add ressOf WriteToScreen)

While True

client = server.AcceptTc pClient() 'Perform blocking call to
accept requests.
Me.Invoke(showM essage, "Connection established.... ")

'Get a stream object for reading and writing.
Dim stream As NetworkStream = client.GetStrea m()

Dim intBytes As Int32
intBytes = stream.Read(Buf ferbytes, 0, Bufferbytes.Len gth)

While (intBytes <0)
'Translate data bytes to a ASCII string
incomingMessage =
System.Text.Enc oding.ASCII.Get String(Bufferby tes, 0, Bufferbytes.Len gth)
Me.Invoke(showM essage, String.Format(" Received message
from client: {0}", incomingMessage .ToString()))
Dim msg As Byte() =
System.Text.Enc oding.ASCII.Get Bytes(incomingM essage)
stream.Write(ms g, 0, msg.Length)

intBytes = stream.Read(Buf ferbytes, 0, Bufferbytes.Len gth)
End While
'shutdown the connection
client.Close()
End While
End Sub

I plan to put the server.Close() command under the Click the event for a
button and declare TcpListener as a global object.

--
TC
Oct 27 '06 #1
1 4026
I am having exactly the same problem. The interesting part is that I
wrote a app that works like a chat app with a sender and a receiver
class that work perfectly. When I now impliment the receiver class into
the enterprise solution we are building I get this error. On the same
machines, with the same configuration.

What's up with that?

I have disabled Windows Firewall on both machines. Could it be a
security issue?

Very dodgy! Any help would be much apreciated.

Thanks
David

Terrance wrote:
I'm trying to create a small messenger program that uses the tcpclient and
tcplistenter objects. When I start the application and run the thread that
fires the tcplistener; once the client sends data then closes the stream and
the connection I receive the message Unable to read data from the transport
connection: An existing connection was forcibly closed by the remote host.
How can I keep the connection listener listening for new traffic?

Here is the code I have:

---------Button Click Event-----------------------------------
Dim t1 As New Thread(AddressO f StartListening)
If btnStartListeni ng.Text = "Start Listening" Then
t1.Name = "ListenThre ad"
t1.IsBackground = True
t1.Start()
ElseIf btnStartListeni ng.Text = "Stop Listening" Then
t1.Abort()
StopListening()
Dim server As TcpListener
server = Nothing
------------------------------------------------------------------------
Private Sub StartListening( )
Try

server = New TcpListener(ipL ocalEndPoint)
server.Start() 'Start listening for client request.
Dim showProgress As New ChangeFormStatu s(AddressOf ChangeStatus)
'Inform user that the app is now listening.

Me.Invoke(showP rogress, status.ONLINE)

Dim client As TcpClient
Dim Bufferbytes(102 4) As Byte 'Buffer for reading data.
Dim incomingMessage As String = Nothing 'Variable for incoming
message
Dim showMessage As New DisplayText(Add ressOf WriteToScreen)

While True

client = server.AcceptTc pClient() 'Perform blocking call to
accept requests.
Me.Invoke(showM essage, "Connection established.... ")

'Get a stream object for reading and writing.
Dim stream As NetworkStream = client.GetStrea m()

Dim intBytes As Int32
intBytes = stream.Read(Buf ferbytes, 0, Bufferbytes.Len gth)

While (intBytes <0)
'Translate data bytes to a ASCII string
incomingMessage =
System.Text.Enc oding.ASCII.Get String(Bufferby tes, 0, Bufferbytes.Len gth)
Me.Invoke(showM essage, String.Format(" Received message
from client: {0}", incomingMessage .ToString()))
Dim msg As Byte() =
System.Text.Enc oding.ASCII.Get Bytes(incomingM essage)
stream.Write(ms g, 0, msg.Length)

intBytes = stream.Read(Buf ferbytes, 0, Bufferbytes.Len gth)
End While
'shutdown the connection
client.Close()
End While
End Sub

I plan to put the server.Close() command under the Click the event for a
button and declare TcpListener as a global object.

--
TC
Nov 24 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3509
by: Galore | last post by:
Hello, I'm trying to make a simple socket application, something like a chat application, but when I run it, it shows the following error when the client connects to the server: "Unable to read data from the transport connection.". I'm posting the code, so if somebody can help I'll be very grateful. private void DoListen() {
1
4192
by: Muscha | last post by:
Hello, Every now and then my application throw this exception: "Unable to read data from the transport connection" And when I break into the Visual Studio, the thread where it failed has none of my code and the following is the call stack:
0
11245
by: Aryeh Holzer | last post by:
Hi, I've been trying to use the weather webservice available from the National Weather Service (NWS), at http://www.nws.noaa.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML. wsdl without success. Here's what I've found so far. When I use .NET 1.0/1.1, and try to call the primary webservice method NDFDgen, the call will succeed if the productType is set to "glance", but fail if set to "time- series".
0
2416
by: quocvuong2005 | last post by:
Hi all ! I have a webservice that contains a Helloworld() method (This return a string type ) and a asp.net application . I call Helloworld method from webservice , it works fine . but when i call this method again , it have problem with error message following: Unable to read data from the transport connection. at System.Net.ConnectStream.BeginRead(Byte buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state) at...
0
2537
by: quocvuong2005 | last post by:
Hi all ! I have a webservice that contains a Helloworld() method (This return a string type ) and a asp.net application . I call Helloworld method from webservice , it works fine . but when i call this method again , it have problem with error message following: Unable to read data from the transport connection. at System.Net.ConnectStream.BeginRead(Byte buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state) at...
0
1315
by: Brent | last post by:
After six months flawless operation, I'm suddenly getting this error: "Unable to read data from the transport connection." The code* hasn't changed, and from what I can see, neither have the IP address, network card, security protocols, etc. The code works fine on other machines, but the critical one -- the one it's supposed to work on -- fails. The stack trace** doesn't seem to help me out, but I thought perhaps someone here could shed...
7
3094
by: Jay Balapa | last post by:
Hello, We have a Pocket PC client application which just connects to our webservice. When a client connects his Pocket PC through his WIFI he gets the following- Unable to read data from the transport connection . I have the same setup and am unable to reproduce this problem. This method just tests the webmethod with a helloworld returned. Any help is greatly appreciated.
6
8163
Cintury
by: Cintury | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql server mobile ce database. Until recently I was synching everything thru a com port serial cable. The devices would connect to the computer thru activesync and are able to acquire an internet connection. The sync for the program occurs thru a website...
0
2065
by: imonline | last post by:
Hi, I have created a asp.net page which posts XML on the web service using .net 2.0. The page and the webservice was working fine but once I converted them to .net 3.5 I have been getting following exception. And I am having this problem on the local machine that is both of them on same machine. Exception: System.Net.WebException was caught
0
8712
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9316
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9177
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7954
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4727
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2524
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2113
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.