0

Hey guys,
I'm writing a small client/server application.

I've got it almost completely working, other than the fact that once the user disconeccts from the server using TcpClient.close he can not reconnect without restarting the app because clientSocket is disposed.


Declaration:

Dim clientSocket As New System.Net.Sockets.TcpClient()

Connect:

clientSocket.Connect(127.0.0.1, 8888)

Disconnect:

clientSocket.Close()

Reconnect (returns error or clientSocket being disposed):

clientSocket.Connect(127.0.0.1, 8888)

So my question is: Is there any way to un-dispose the Tcpclient or is there a way to disconnect without disposing the Tcpclient?


Thanks for the help
-Zander

2
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by Zandermander
1

Is there any way to un-dispose the Tcpclient

No.

is there a way to disconnect without disposing the Tcpclient

AFAIK no.

once the user disconeccts from the server using TcpClient.close he can not reconnect without restarting the app because clientSocket is disposed

TcpClient.Close disposes the socket as you noticed. You have to create a new socket before calling Connect method

Dim clientSocket As System.Net.Sockets.TcpClient

clientSocket = New System.Net.Sockets.TcpClient
clientSocket.Connect(127.0.0.1, 8888)
Votes + Comments
Thanks for all your continuous help in my VB.NET endeavors!!! Your a genius man!
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.