This tutorial speaks about the creation of TCP/IP socket and use of this connection between applications. The client-server architecture can be local or distributed over the network. I will discuss it in a simple manner which would help you in developing a small chat-like application. Based on this application, I will let you know how to develop an Instant LAN Messenger in WPF using Socket Programming.
The .NET Framework provides us a higher level of abstraction upon sockets in the form of TcpListener and TcpClient. TcpListener is a high level interface for server and TCPClient is for client application. They are both implemented over sockets but provide easier and high level interface. NetworkStream is used for an end to end communication between TcpListener and TcpClient. We can use both stream reader and writer over NetworkStream through StreamReader and StreamWriter.
I will use two namespaces System.Net and System.Net.Sockets which are required for Socket Programming. Basically, TCPListener class provides simple methods to listen and accept incoming connection requests whereas, TcpClient class implements a socket for sending and receiving data using TCP.
IPAddress class provides an Internet Protocol (IP) address and it’s used by clients to get connected with the server.
For the code of TcpServer and TcpClient, please visit Redmond Pie.
No comments:
Post a Comment