This article contains synoptical analysis of multi socket programming for client side. Doing coding for client side in socket programming & doing coding it in muliti socket programming; is different.
Multi socket programming is few steps ahead in socket programming as one client is connected to one server who is listing at particular port in traditional socket programming whereas one client get connected to two servers at different ports on same machine or on different machines in multi socket programming.
This analysis is done on Microsoft Visual Studio 2003 and .Net Framework 1.1. This analysis is purely meant for intermediate and/or expert professionals of Microsoft Visual Studio 2003 and .Net Framework 1.1. If you have firewall on your system make sure it won't disallow connection.
In this report I have added order analysis and flow analysis of execution for these applications; this will definitely enhance your gained knowledge. It is better to understand the order and flow of execution for a sound professional in software engineering. If you think that you are expert in software development you can directly switch your study to these (order analysis and flow analysis).
Some professionals may find the scope of explanation from technical point of view but as a sound understanding of these applications (i.e. server and client) it is sufficient. If I write whole things, this will put me on long journey to complete and make puzzle and confuse you too. Do remember one thing that there should be limit of explanation depending on requirement and that limit is achieved here for our requirement and purpose. Even if you want to explore more you can proceed; I Welcome.
I have included at the end complete references (i.e. their definition, overview, public constructors, public methods, protected methods, properties etc.) of TcpListener Class, TcpClient Class. Make sure that you should read them as I have used TcpListener Class and TcpClient Class for multi socket programming.
Using the code
Multiple Sockets Programming
What is multi socket programming? Technically it is way of socket programming in which two sockets connecting to either two different servers or same server. What exactly multi socket programming is? For that understand what traditional socket programming is, simultaneously with multi socket programming.
Socket or sockets are logical connections that are created to connect the computers to each others. A port number and a host IP Address/Host name is required to create a socket. Thread or threads are that pieces of a process or program that are assigned some resources, such as file, I/O, and so forth and are able to run individually. Multithreading means many threads of a process can be run on a single processor assigning them an equal time slice and priority, each feeling that it is the only process running.
We implement socket programming in case whenever there is need to make a communication between two machines (here machine stands for computer system), in which one machine act as server and while other as client.
The role of server is to keep listening to the incoming connection's request(s) at particular port. Client sends a request to server to establish a communication through ipaddress of server (or name of server) and port no at which server is listening. Now what happen in multi socket programming is that a client sends request of connection to two or more servers those are listening at their respective port in consideration.
It is up to the server(s) to accept connection request (send by client) or to reject it. If server(s) accepts the connection a virtual pipeline (technically a socket) is created for the communication of messages between server and client to and fro. During the time when a client has active connection to server(s) it can send and receive data from server(s), and then close the connection. These connections are expensive in terms of resources utilized. Server (s) can also restricted to limited number of clients to connect. Again I am repeating that it is server/client architecture because one the computer will act as a server (which is responding to client messages) whiles all other computer behaves as clients (that only send request to server to establish a communication).
A beautiful complexity exhibits by multi socket programming is that a server(s) sends data to any connected client or to all connected clients (that is broadcasting) is to be read by client(s) but how the client(s) came to know which server has send this data. Other difficulty is when either side sends data to other side is supposed to read it but how the other side came to know that any data has arrived. I will explain these issues in detail in later part of this document so stick to it.
Coding Analysis- The Client
Here I am exploring simple client for better understanding. This client connects to two different servers and start communicating with them. The total numbers of functions which are used in this are listed as under:
Same important thing I write in my every document is before proceeding that all these functions are listed on structural basis. If anyone is trying to find syntax errors (e.g. no of arguments in Form2_Load event) please forgive me. Thanks to God.
Now one more thing following are the imports files for this project's class
Both these files are important as .net provide enrich set of functions through these classes.
Private marDataOne(1024) As Byte
Private mobjClient, mobjClientSec As TcpClient
Private Delegate Sub callDisplayText(ByVal t As String)
<p>Elaborating Function </p>
<p>The full code is as