Click here to Skip to main content
12,631,574 members (33,243 online)
Click here to Skip to main content
Add your own
alternative version

Stats

20.8K views
13 bookmarked
Posted

A Synoptic Analysis Of Multi Socket Programming-The Client

, 2 Oct 2007
Rate this:
Please Sign up or sign in to vote.
This Article Contains In Snoptical Analysis Of Multi Socket Programming (Part I)- The Client

Introduction

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.


Background

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:

i) Form2_Load()
ii) DoReadOne()
iii) DoReadSec()
iv) DisplayText()
v) btnSendFirst_Click()
vi) SendForFirst()
vii) btnSendSecond_Click()
viii) SendForSecond()
ix) btnAllServer_Click()
x) MarkAsDisconnected()

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
Imports System.Net
Imports System.Net.Sockets

Both these files are important as .net provide enrich set of functions through these classes.

'declaring form level variables 
Private marDataOne(1024) As Byte 
Private mobjClient, mobjClientSec As TcpClient 
Private Delegate Sub callDisplayText(ByVal t As String) 
<p>'marDataOne' is an array of bytes which is used to store data which is coming from server in 'DoReadOne()' function. </p>

<p>'mobjClient' & 'mobjClientsec' are objects of TcpClient class & are used to connect to particular servers at concern port see in 'Form2_Load()'.</p>

<p>Elaborating Function 'Form2_Load()' </p>

<p>The full code is as under </p>

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Er. Nishant Singh Chauhan
Web Developer
Unknown
Er. Nishant Singh Chauhan is presently working in H.T.N. Co. Ltd. This organization is located in between of magnificent, mesmerizing & mischievous hills of Phuket, Thailand.

Er. Nishant Singh Chauhan belongs to Gurgaon-India. But he has moved himself to this location in the month of September 2007. He is found of playing programm (playing; because of sporadical physical work). His first love was (yet it is retained to continue) computer P-II with 64 MB Ram and 10 GB hard disk. He likes writting & has been publishing his documents, articles & knowledge in electronic form at Google from few time in past. His vast knowledege of socket programming including multi socket proramming seperates him from other computer geek.

He holds knowledge in VB.Net, C#.Net, Asp.Net, Java, Javascript, HTML, C, C++. Even his professional tincture bends himself towards .NET yet he has been providing coaching in others languages since 2003.

He holds bachelor degree in computer science & engineering with Hons. & was pursuing his master in magnagement in Information Technology Managenet & International Business Managenent from India but due to moving out from India to Thailand he had to hang his master. He is member of prestigious Association of Computer Machinery, New York, USA. You can mail your problems (and suggestions too) to this author at following mail address:
nishant.c@hoteltravel.com

You may also be interested in...

Pro
Pro

Comments and Discussions

 
GeneralMy vote of 1 Pin
Pablo Castillo26-Mar-10 12:26
memberPablo Castillo26-Mar-10 12:26 
GeneralHorizontal scroll. Pls format Pin
Paras Shah4-Oct-07 9:33
memberParas Shah4-Oct-07 9:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161205.3 | Last Updated 2 Oct 2007
Article Copyright 2007 by Er. Nishant Singh Chauhan
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid