System.Net.Sockets namespace
Before we go any further, download the source code attached with this article.
Extract the zip file to a folder say c:\Temp you will see following two folders
:
Server
Client
In the Server folder there will be one EXE. And in the client there will
be the source code in C# that is our client. There will be one file called
SocketClient.sln which the solution file. If you double
click that your VS.NET will be launched and you will see the project SocketClientProj in
the solution. Under this project you will have SocketClientForm.cs file.
Now build the code (by pressing Ctrl-Shift-B)
and run the code you will see the following dialog box:
As you
can see the dialog box has a field for Host IP address ( which is the IP address
of the machine on which you will run the Server Application, located under
Server folder). Also there is a field where you can specify port number at
which
the Server is listening. The server app I have provided
here listens at port 8221. So I have specified port to be 8221.
After specifying these parameters we need to connect to the server. So pressing
Connect will connect to the server and to close the connection press Close.
To send some data to the server type some data in the field near the button
name Tx and if you press Rx the application will block unless there is
some data to read.