Index

C# Programming - Sockets

The purpose of this article is to understand the sockets.
There are several flavors of socket programming - like client side, server side, blocking or synchronous, non-blocking or asynchronous etc.

  1. A socket is like a handle to a file.
  2. Socket programming resembles the file IO as does the Serial Communication.
  3. We can use sockets programming to have two applications communicate with each other. The application are typically on the different computers but they can be on same computer.
  4. For the two applications to talk to each either on the same or different computers using sockets one application is generally a server that keeps listening to the incoming requests and the other application acts as a client and makes the connection to the server application.
  5. The server application can either accept or reject the connection. If the server accepts the connection, a dialog can begin with between the client and the server.
  6. Once the client is done with whatever it needs to do it can close the connection with the server.
  7. Connections are expensive in the sense that servers allow finite connections to occur.
  8. During the time client has an active connection it can send the data to the server and/or receive the data. The complexity begins here. When either side (client or server) sends data the other side is supposed to read the data. But how will the other side know when data has arrived. There are two options - either the application needs to poll for the data at regular intervals or there needs to be some sort of mechanism that would enable application to get notifications and application can read the data at that time. Well , after all Windows is an event driven system and the notification system seems an obvious and best choice and it in fact is.
Index