Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

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
Posted

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?

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

The idea would be to allow the user the option of keeping the connection alive or letting it disconnect.

 

Thanks for the information.

 

ZeroEffect

If you can't find it, Build It.

 

There is no place Like 127.0.0.1 also don't forget 1 + 1 = 10

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...