' Collection of code snippets by Arne Vajhøj 
' (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
Imports System
Imports System.IO
Imports System.Net.Sockets
Imports System.Threading

Class ChatClient
    Public Shared Sub Main(ByVal args As String())
        Dim client As TcpClient = New TcpClient("localhost", 50000)
        Dim wrt As StreamWriter = New StreamWriter(client.GetStream)
        Call (New Thread(AddressOf (New Reader(client)).Run)).Start
        Dim line As String
        line = Console.ReadLine
        While Not (line Is Nothing)
            wrt.WriteLine("SEND " + line)
            wrt.Flush
            line = Console.ReadLine
        End While
        wrt.WriteLine("EXIT")
        wrt.Flush
        wrt.Close
        client.Close
    End Sub
End Class 

Class Reader
    Private rdr As StreamReader

    Public Sub New(ByVal cli As TcpClient)
        rdr = New StreamReader(cli.GetStream)
    End Sub

    Public Sub Run()
        Try
            Dim line As String
            line = rdr.ReadLine
            While Not (line Is Nothing)
                Console.WriteLine(line)
                line = rdr.ReadLine
            End While
        Catch e As Exception
            ' nothing
        End Try
    End Sub
End Class 
