VB.NET Client Socket Program

The Socket Programming has two sections.

1. Server Socket Program

2. Client Socket Program

The Client Socket Program serves as a seamless extension of the Server Socket Program, culminating in a comprehensive and integrated networking solution. This meticulously crafted Client Socket Program manifests itself as a sophisticated Windows-based application, brimming with features and functionality.

When initiating a connection, the client skillfully interfaces with the Server Socket Program by establishing a communication channel through Port 8888. In this specific instance, the IP Address (Computer Name) specified is, as both the server and client are operating within the confines of a single machine. This judicious selection enables streamlined communication and seamless interaction between the client and server, fostering an environment of swift and efficient data transfer.

clientSocket.Connect("", 8888)

Upon successful connection establishment, the client diligently engages in the reading and writing of data from the NetworkStream, which serves as the conduit for seamless communication. The client program's execution commences with a notable message, proclaiming the initiation of the client itself, thereby signifying its readiness to participate in the networked environment.


Moreover, situated at the bottom of the client program's interface, lies a button of significance. Upon pressing this button, a momentous event transpires: the client conveys a carefully crafted message to the server, showcasing its ability to transmit information. Concurrently, the client remains ever receptive, eagerly anticipating a response from the server. This dynamic interplay highlights the bidirectional nature of the communication process, as data flows effortlessly between the client and server, fostering a harmonious exchange of information.

Full Source VB.NET
Imports System.Net.Sockets Imports System.Text Public Class Form1 Dim clientSocket As New System.Net.Sockets.TcpClient() Dim serverStream As NetworkStream Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Dim serverStream As NetworkStream = clientSocket.GetStream() Dim outStream As Byte() = _ System.Text.Encoding.ASCII.GetBytes("Message from Client$") serverStream.Write(outStream, 0, outStream.Length) serverStream.Flush() Dim inStream(10024) As Byte serverStream.Read(inStream, 0, CInt(clientSocket.ReceiveBufferSize)) Dim returndata As String = _ System.Text.Encoding.ASCII.GetString(inStream) msg("Data from Server : " + returndata) End Sub Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load msg("Client Started") clientSocket.Connect("", 8888) Label1.Text = "Client Socket Program - Server Connected ..." End Sub Sub msg(ByVal mesg As String) TextBox1.Text = TextBox1.Text + Environment.NewLine + " >> " + mesg End Sub End Class


Brfore you run the Client Socket Program you should start Server Socket Program first . For more details of running this program , take a look at the VB.NET Socket Programming .