Hello,
Lets assume I have an instance of TCPClient.
I connect successfully and have the socket stream working.
I when call the .close() method the TCPClient instance....so far so good.
Now when I come to once again reconnect by doing as before:
MyX = New TcpClient
MyX.Connect("localhost", 5000)
I get an error so I catch an exception which says "Unable to read data from
transport stream".
I catch the exception in DoRead()
Why is this?
Just in case below is my connection code (the entire sub):
***********CODE FOLLOWS************
'//Lets get the host name so we can later find out our IP
Dim strHostName As String = System.Net.Dns.GetHostName.ToString
If boxIPAddressToConnectTo.Text = "" Or boxIPAddressToConnectTo.Text =
"localhost" Then
'//Make new instance of TCPClient
MyX = New TcpClient
MyX .Connect("localhost", 5000)
Else
End If
'//Display the time and date
DisplayText(">> Date: " & System.DateTime.Now.ToLongDateString() & vbCrLf)
DisplayText(">> Time: " & System.DateTime.Now.ToLongTimeString() & vbCrLf)
'//Initialize a read stream running in its own background thread
MyAdamHonekChatterClient.GetStream.BeginRead(Other UserText, 0, 1024,
AddressOf DoRead, Nothing)
'//Send some text now indicating this user has logged on
SendUserText(">> " & boxMyNickName.Text & " is currently online.")
'Setup status of form controls ready for a new chat session
boxMyNickName.Enabled = False
boxUserText.ReadOnly = False
boxUserTextDisplay.ReadOnly = True
btnSendUserText.Enabled = True
boxUserText.Enabled = True
btnSignIn.Enabled = False
btnChangeFont.Enabled = True
btnChangeFontColor.Enabled = True
'//Inform the user that they have signed-in and are online ready to chat
StatusBar.Text = "You are currently online as " & boxMyNickName.Text & "
(Your IP: " &
(System.Net.Dns.GetHostByName(strHostName).Address List(0).ToString) & ")"
***********
Many thanks,
Adam