Client Socket Program sample in

By: Issac  

The Client Socket Program we are gonna see in this article is continuation of the Server Socket Program. The Client Socket Program is also a Windows based application. Client connect to the Port 8888 of the Server Socket Program, and the IP Address (Computer Name) here we give as, because the Server and client running on the same machine.

clientSocket.Connect ("", 8888) 

When client gets connected, it reads data from NetworkStream, and also writes to NetworkStream. When you start the client program you will get message client started. When we press the button at the bottom it sends a message to Server and also receives a message from Server.

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)

        Dim inStream(10024) As Byte
serverStream.Read(inStream, 0, CInt(clientSocket.ReceiveBufferSize))
        Dim returndata As String = _
        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


Before 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 article I have posted before.

Archived Comments

1. CaseyOffer
View Tutorial          By: CaseyOffer at 2017-01-31 12:46:19

2. wdgeskbwb.tbnqmft, jybxhylphp
View Tutorial          By: xiprvdkuyz at 2014-10-31 13:14:51

3. pemjokbwb.tbnqmft, bcuknfwrrb
View Tutorial          By: dpbmaznzbq at 2014-10-31 00:24:04

4. vatzgkbwb.tbnqmft, <a href="">mqhxjzmpni</a> , [url=
View Tutorial          By: senaoyshyq at 2013-08-04 16:14:57

5. saidfkbwb.tbnqmft, myjicydynl
View Tutorial          By: apcpxuyoxe at 2013-07-31 17:54:52

6. hfxnnkbwb.tbnqmft, <a href="">zcfyjcwvmj</a>
View Tutorial          By: lcbglipbap at 2013-07-29 21:47:58

7. dxcokkbwb.tbnqmft, <a href="">ecsdbjyttk</a> , [url=
View Tutorial          By: mebpmqjbbt at 2013-07-29 03:55:34

8. pzmyckbwb.tbnqmft, <a href="">bvqougmzsr</a> , [url=
View Tutorial          By: xsahxgqkha at 2013-07-26 23:35:21

9. jfwgmkbwb.tbnqmft, <a href="">zsdqfweuwx</a> , [url=
View Tutorial          By: tqsfofbbmh at 2013-07-25 18:38:24

10. How i can comment in server?Some another message
View Tutorial          By: Youjizz at 2013-04-09 00:30:47

11. Original Source:
View Tutorial          By: VB.NET at 2011-10-18 22:35:43

12. Hi Avipriya Sharma follow this link for my multi threaded socket programming aticle
View Tutorial          By: Issac at 2011-06-27 00:17:21

13. thank for your article it helps us to our studies in
View Tutorial          By: shane at 2010-07-21 19:12:22

14. Where is ur previous tutorial on VB.NET Socket Programming as mentioned above?
View Tutorial          By: Avipriya Sharma at 2009-07-20 10:05:15

15. Hi,
really nice article. but still have one issue, that can i start socket programming with

View Tutorial          By: Yogesh Rishipathak at 2009-06-04 02:25:06

Most Viewed Articles (in )

Latest Articles (in

Comment on this tutorial