Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Module Module1
Sub Main()
Try
Dim ipAddress As IPAddress = ipAddress.Parse("127.0.0.1") 'storing the IPAddress
Dim tcpListener As New TcpListener(ipAddress, 8000) 'creating the listener
tcpListener.Start() 'starting the listener
System.Console.WriteLine("the server is running at port 8000...")
Dim myendpoint As IPEndPoint
myendpoint = CType(tcpListener.LocalEndpoint, IPEndPoint)
System.Console.WriteLine("The local end point address is " + myendpoint.Address.ToString + "and port is " + myendpoint.Port.ToString)
System.Console.WriteLine("Waiting for Connection....")
Dim soc As Socket = tcpListener.AcceptSocket() 'creating the socket and accepting the socket from listener
myendpoint = CType(soc.RemoteEndPoint(), IPEndPoint)
System.Console.WriteLine("Connection Accepted From " + myendpoint.Address.ToString())
Dim byteData(100) As Byte
Dim size As Integer = soc.Receive(byteData) 'receiving the data from socket and reading its size
Console.WriteLine("Received")
For i As Integer = 0 To size
Console.Write(Convert.ToChar(byteData(i))) 'Convert.ToChar will convert the byte value into character
Next
Console.WriteLine()
Dim ascenc As New ASCIIEncoding
Console.WriteLine("Sending Acknoledgement")
soc.Send(ascenc.GetBytes(("The string was recieved by the server."))) 'sending the acknoledgement message
soc.Close() 'Closing the socket
tcpListener.Stop() 'Stopping the listener
Catch ex As Exception
Console.WriteLine("Error ..." + ex.ToString()) 'Printing the exception if any
End Try
End Sub
End Module
Client.vb