By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,270 Members | 1,319 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,270 IT Pros & Developers. It's quick & easy.

Socket connection not re-usable?

P: n/a
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


Nov 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.