Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class Client
- Private client As TcpClient
- Private clientPacket As String
- Public Sub New(ByVal client As TcpClient)
- 'New client connects
- Me.client = client
- client.GetStream().BeginRead(New Byte() {0}, 0, 0, AddressOf Read, Nothing)
- End Sub
- Public Sub Read(ByVal ar As IAsyncResult)
- Dim reader As New StreamReader(client.GetStream())
- clientPacket &= reader.ReadLine()
- client.GetStream().BeginRead(New Byte() {0}, 0, 0, AddressOf Read, Nothing)
- End Sub
- Public Sub Send(ByVal Message As String)
- Dim writer As New StreamWriter(client.GetStream())
- writer.WriteLine(Message)
- writer.Flush()
- End Sub
- End Class
- Public Class frmMain
- Dim Listener As TcpListener
- Dim ListenerThread As Thread
- Private Sub StartListening()
- ListenerThread = New Thread(AddressOf Listen)
- ListenerThread.IsBackground = True
- ListenerThread.Name = "listener"
- ListenerThread.Start()
- End Sub
- Public Sub Listen()
- Listener = New TcpListener(IPAddress.Any, 7008)
- Listener.Start()
- While (True)
- Dim c As New Client(Listener.AcceptTcpClient())
- End While
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement