VB.NET: Connect and Disconnect using System.Net.Sockets

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

I don't have access to a system to try this on, but I think what is
happening is you have to create a new tcpclient every time you want to open
the connection. I'm new at this but give it a try. Just trying to help
out. Someone smarter might want to verify this.

Imports System.Net.Sockets

Module Connection

Dim tcpC As TcpClient

Public Sub Connect()

'Connect from this to the server at Port 6970
Try
tcpC = new TcpClient
tcpC.Connect("152.138.40.200", 6970)
Catch e As Exception
Console.WriteLine(e.ToString())
End Try
End Sub

Public Sub Disconnect()
if not tcpC is nothing then
tcpC.Close()
tcpC = nothing
end if
End Sub

End Module
 
Say i have declare a module for connection and two buttons...

one button has the method connect() and
the other has the method disconnect()....

how do i actually connect after i had disconnect my tcpC...
I could not connect after i disconnect my connection...

Imports System.Net.Sockets

Module Connection

Dim tcpC As New TcpClient

Public Sub Connect()

'Connect from this to the server at Port 6970
Try
tcpC.Connect("152.138.40.200", 6970)
Catch e As Exception
Console.WriteLine(e.ToString())
End Try
End Sub

Public Sub Disconnect()
tcpC.Close()
End Sub

End Module

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top