ZeroEffect Posted February 13, 2009 Posted February 13, 2009 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. 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 won't exit until the operation has been completed This is the code I am using. '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 shouldn't 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 Quote If you can't find it, Build It. There is no place Like 127.0.0.1 also don't forget 1 + 1 = 10
Administrators PlausiblyDamp Posted February 13, 2009 Administrators Posted February 13, 2009 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 can't maintain the connection and need to keep disconnecting and reconnecting? If you do not require permanent connection would UDP be a better option? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
ZeroEffect Posted February 13, 2009 Author Posted February 13, 2009 The idea would be to allow the user the option of keeping the connection alive or letting it disconnect. Thanks for the information. ZeroEffect Quote If you can't find it, Build It. There is no place Like 127.0.0.1 also don't forget 1 + 1 = 10
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.