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

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)
commented: Thanks for all your continuous help in my VB.NET endeavors!!! Your a genius man! +1

Worked perfectly, Thanks, once again, Teme!

-Zander

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.