TCPClient

ZeroEffect

Well-known member
Joined
Oct 24, 2004
Messages
180
Location
Detroit, MI
Here is what I am trying to do. I am using TCPClient to connect to another application send data and close the connection. Then when more data is is received to reconnect and send data to the same application. I can get this to work once. then I get this message.

Code:
Once the socket had been disconnected, you can only reconnect again asynchronously,
and only to a different EndPoint. BeginConnect must be called on a thread
that wont exit until the operation has been completed

This is the code I am using.

Code:
This is created in another part of the application

Dim groupEP As New IPEndPoint(IPAddress.Any, 20000)
tRemote1 = New TcpClient(groupEP)

This is called from another sub.

tRemote1.Client.Connect(strRemotePort1IP, strRemotePort1Port)
tRemote1.GetStream.Write(sendBytes1, 0, sendBytes1.Length)
tRemote1.Client.Disconnect(True)
tRemote1.Client.Shutdown(Net.Sockets.SocketShutdown.Both)

My thought is that I shouldnt have to recreate the object everytime I use it. I should be able to just open and close it or am I mistaken.

Thanks for you help,

ZeroEffect
 
I think you will need to create a new client for each connection - TCP is a connection orientated protocol and the TcpClient reflects that in how it operates.

Is there a reason you cant maintain the connection and need to keep disconnecting and reconnecting? If you do not require permanent connection would UDP be a better option?
 
The idea would be to allow the user the option of keeping the connection alive or letting it disconnect.

Thanks for the information.

ZeroEffect
 

Similar threads

P
Replies
0
Views
174
Policy standard local admin account with Active Di
P
Back
Top