========== client ============
==========================
Try
Dim tcpClient As New System.Net.Sockets.TcpClient
tcpClient.Connect("24.50.177.229", 9000)
Dim networkStream As NetworkStream = tcpClient.GetStream
If networkStream.CanWrite Then
Try
Dim sendBytes As Byte() = Encoding.ASCII.GetBytes("someone went to test
website")
networkStream.Write(sendBytes, 0, sendBytes.Length)
Catch ex As Exception
End Try
End If
Catch ex As Exception
Response.Write(ex.Message)
Response.Write(ex.Source)
Response.Write(ex.HelpLink)
End Try
======= server ==============
Const tcpPort As Integer = 9000
Dim localAddr As Net.IPAddress = Net.IPAddress.Parse("127.0.0.1")
Dim tcpListener As New Net.Sockets.TcpListener(localAddr, tcpPort)
Dim listnerThread As New Thread(AddressOf ListenForData)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.txtOutputMessages.Text += "Starting listener..." &
ControlChars.CrLf
tcpListener.Start()
Me.txtOutputMessages.Text += "Listener started, waiting for
connection..." & ControlChars.CrLf
Application.DoEvents()
listnerThread.Start()
End Sub
Private Sub ListenForData()
Me.txtOutputMessages.Text += "Thread started, waiting for data..." &
ControlChars.CrLf
Try
Dim tcpClient As TcpClient = tcpListener.AcceptTcpClient
Me.txtOutputMessages.Text += "Connection Accepted..." &
ControlChars.CrLf
Dim networkStream As NetworkStream = tcpClient.GetStream()
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
Do
networkStream.Read(bytes, 0,
CInt(tcpClient.ReceiveBufferSize))
If networkStream.CanRead Then
Me.txtOutputMessages.Text += "Client Sent: " &
Encoding.ASCII.GetString(bytes) & ControlChars.CrLf
End If
Loop
Catch ex As Exception
Me.txtOutputMessages.Text = ex.Message
tcpListener.Stop()
End Try
End Sub
==========================