Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Net
- Imports System.Net.Sockets
- Imports System.Text
- Module Module1
- Dim _Client As Socket
- Dim readerThread As Threading.Thread
- Sub Main()
- _Client = New Socket(SocketType.Stream, ProtocolType.Tcp)
- _Client.Connect(New IPEndPoint(IPAddress.Parse(RequestLine("Enter an IP Adress")), Integer.Parse(RequestLine("Enter a port"))))
- readerThread = New Threading.Thread(Sub()
- While True
- Dim Failed As Boolean = False
- Dim Count As Integer
- Dim R() As Byte
- If _Client.Available > 0 Then
- Dim Buffer(_Client.Available - 1) As Byte
- SyncLock _Client
- _Client.Receive(Buffer, Buffer.Length, SocketFlags.None)
- End SyncLock
- Console.WriteLine(Encoding.UTF8.GetString(Buffer).Replace(vbNullChar, ""))
- End If
- End While
- End Sub)
- readerThread.Start()
- While True
- Dim M As String = String.Empty
- M = RequestLine("Enter a message")
- If Not M.Equals(String.Empty) Then
- SyncLock _Client
- _Client.Send(Encoding.UTF8.GetBytes(M))
- End SyncLock
- End If
- End While
- End Sub
- Public Function RequestLine(ByVal Message As String) As String
- Console.WriteLine(Message)
- Return Console.ReadLine
- End Function
- End Module
Advertisement
Add Comment
Please, Sign In to add comment