473,769 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 4031
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
3520
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
4199
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
11253
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
2417
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
2539
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
1317
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
3098
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
2068
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
10210
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
10043
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...
1
9990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8869
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...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6672
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
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2814
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.