473,407 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Socket connection not re-usable?

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
0 826

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

Similar topics

0
by: Hameed Khan | last post by:
hi all, i am getting some problems with my first socket script. can any one of you point me why this is happening. the server script suppose to accept one connection at a time and send countdown...
2
by: Droopy | last post by:
Hi, I try to implement a reusable socket class to send and receive data. It seems to work but I have 2 problems : 1) I rely on Socket.Available to detect that the connection is closed (no...
0
by: Droopy | last post by:
Hi, I try to implement a reusable socket class to send and receive data. It seems to work but I have 2 problems : 1) I rely on Socket.Available to detect that the connection is closed (no...
0
by: Mangabasi | last post by:
Howdy, I would like to use the Synthesis Toolkit for a demo. I downloaded the STK from http://ccrma.stanford.edu/software/stk/index.html. It seems very powerful and user friendly. There are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...
0
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...

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.