' Collection of code snippets by Arne Vajhøj 
' (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
﻿Imports System
Imports System.IO
Imports System.Net.Sockets

Namespace SocketDemo.Text.High.Client
    Public Class Program
        Private Const HOST As String = "localhost"
        Private Const PORT As Integer = 12345
        Public Shared Sub Main(args As String())
            ' open connection
            Dim cli As New TcpClient(HOST, PORT)
            ' get reader and writer
            Dim stm As NetworkStream = cli.GetStream()
            Dim sr As New StreamReader(stm)
            Dim sw As New StreamWriter(stm)
            Console.WriteLine("(connected)")
            ' send a and b
            Dim a As Integer = 123
            Dim b As Integer = 456
            sw.WriteLine(a & " " & b)
            sw.Flush()
            ' receive c and print
            Dim c As Integer = Integer.Parse(sr.ReadLine())
            Console.WriteLine(c)
            ' send v
            Dim v As String = "ABC"
            sw.WriteLine(v)
            sw.Flush()
            ' receive v2 and print
            Dim v2 As String = sr.ReadLine()
            Console.WriteLine(v2)
            ' close connection
            sr.Close()
            sw.Close()
            cli.Close()
            Console.ReadKey()
        End Sub
    End Class
End Namespace
