1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
Const portNo As Integer = 7879
Dim localAdd As System.Net.IPAddress = _
IPAddress.Parse("127.0.0.1")
Dim listener As New TcpListener(localAdd, portNo)
listener.Start()
Console.WriteLine("Listening...")
Dim TcpClient_0 As TcpClient
TcpClient_0 = listener.AcceptTcpClient()
Dim NWStream As NetworkStream = TcpClient_0.GetStream
Dim bytesToRead(TcpClient_0.ReceiveBufferSize) As Byte
Dim numBytesRead As Integer
'---read incoming stream
numBytesRead = NWStream.Read(bytesToRead, 0, CInt(TcpClient_0.ReceiveBufferSize))
'---write back the text
' Console.WriteLine("Sending back : " & _
' Encoding.ASCII.GetString(bytesToRead, 0, numBytesRead))
' NWStream.Write(bytesToRead, 0, numBytesRead)
TcpClient_0.Close()
listener.Stop()
Console.ReadLine() |