Friday, October 19, 2007

Sockets in Visual Studio using Visual Basic.net (VB.net)

I created this code to open a socket connection in Visual Studio using VB.net:

Dim winsock1 As New Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp)
Dim myIP As New IPAddress(IPAddress.Parse("127.0.0.1").GetAddressBytes())
Dim myPort As Integer = 23
Dim myIPend As New IPEndPoint(myIP, myPort)

Public Function Sockets()
If (winsock1.Connected = True) Then
winsock1.Close()
End If

winsock1.Connect(myIPend)


Do While (winsock1.Connected <> True)
Loop

If winsock1.Connected = True Then
winsock1.DoStuff()
End If

If (winsock1.Connected = True) Then
winsock1.Close()
End If

Do While (winsock1.Connected <> True)
Loop

End Function



No comments: