[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] tcp [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Net.Sockets.TcpClient()
tcp.Connect([/SIZE][SIZE=2][COLOR=#800000]"www.microsoft.com"[/COLOR][/SIZE][SIZE=2], 80)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] ip [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Net.IPEndPoint = [/SIZE][SIZE=2][COLOR=#0000ff]DirectCast[/COLOR][/SIZE][SIZE=2](tcp.Client.RemoteEndPoint, Net.IPEndPoint)
MsgBox(ip.Address.ToString & " " & [SIZE=2]ip.Port.ToString)[/SIZE]
[/SIZE]
Dim mytcpclient As TcpClient = mylistener.AcceptTcpClient
Dim ip As Net.IPEndPoint = DirectCast(tcpclient.Client.RemoteEndPoint, Net.IPEndPoint)
Dim strip As String = ip.Address.ToString & " " & ip.Port.ToString
tcpclient.Client
[SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] example()
[/SIZE][SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][SIZE=2] myTcp [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] myTcpClient
myTcp.Connect("www.microsoft.com", 80)
[/SIZE][SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][SIZE=2] ip [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Net.IPEndPoint = myTcp.remoteIP
MsgBox(ip.Address.ToString & " " & ip.Port.ToString)
[/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][SIZE=2] myTcpClient
[/SIZE][SIZE=2][COLOR=#0000ff]Inherits[/COLOR][/SIZE][SIZE=2] Net.Sockets.TcpClient
[/SIZE][SIZE=2][COLOR=#0000ff] Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]ReadOnly [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Property[/COLOR][/SIZE][SIZE=2] remoteIP() [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Net.IPEndPoint
[/SIZE][SIZE=2][COLOR=#0000ff] Get
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff] Return [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]DirectCast[/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].Client.RemoteEndPoint, Net.IPEndPoint)
[/SIZE][SIZE=2][COLOR=#0000ff] End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Get
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff] End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Property
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class
[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] tcpex2()
[/SIZE][SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][SIZE=2] ip [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Net.IPAddress = Net.IPAddress.Parse("127.0.0.1")
[/SIZE][SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][SIZE=2] tcpL [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Net.Sockets.TcpListener(ip, 8000)
tcpL.Start()
[/SIZE][SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][SIZE=2] so [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Net.Sockets.Socket = tcpL.AcceptSocket
tcpL.Stop()
[/SIZE][SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][SIZE=2] myTcp [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] myTcpClient(so)
[/SIZE][SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][SIZE=2] remIP [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Net.IPEndPoint = myTcp.remoteIP
MsgBox(remIP.Address.ToString & " " & remIP.Port.ToString)
[/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][SIZE=2] myTcpClient
[/SIZE][SIZE=2][COLOR=#0000ff]Inherits[/COLOR][/SIZE][SIZE=2] Net.Sockets.TcpClient
[/SIZE][SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2]()
[/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] so [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Net.Sockets.Socket)
[/SIZE][SIZE=2][COLOR=#0000ff] Me[/COLOR][/SIZE][SIZE=2].Client = so
[/SIZE][SIZE=2][COLOR=#0000ff] Me[/COLOR][/SIZE][SIZE=2].Active = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]ReadOnly [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Property[/COLOR][/SIZE][SIZE=2] remoteIP() [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Net.IPEndPoint
[/SIZE][SIZE=2][COLOR=#0000ff]Get
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff] Return [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]DirectCast[/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].Client.RemoteEndPoint, Net.IPEndPoint)
[/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Get
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Property
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class
[/COLOR][/SIZE]
Dim ip As Net.IPAddress = Net.IPAddress.Parse("127.0.0.1")
Dim tcpL As New Net.Sockets.TcpListener(ip, 8000)
tcpL.Start()
Dim tcpclient As Net.Sockets.TcpClient = tcpL.AcceptTcpClient()
Dim remIP As Net.IPEndPoint = DirectCast(tcpclient.Client.RemoteEndPoint, Net.IPEndPoint)
MsgBox(remIP.Address.ToString & " " & remIP.Port.ToString)
ex.Message = "Unable to cast object of type 'System.Net.Sockets.AcceptAsyncResult' to type 'System.Net.Sockets.TcpClient'."
Listening_Port = CInt(txtListeningPort.Text)
TCPL = New TcpListener(Net.IPAddress.Any, Listening_Port)
TCPL.Start()
ListBox1.Items.Add("Waiting Connection From Client PC...")
TCPL.BeginAcceptTcpClient(AddressOf OnConnect, Nothing)