13. Socket Programming Based Group Chat Application - Part 2



Hello folks!
Welcome to this blog series.In previous blog we have seen basic theoretical background related to project based on socket programming ,now in this blog we will see some more concepts such as socket,TCP/IP which are related to this project.
In this project we are trying to establish connection between multiple people at the same time so they are able to chat with person by establishing server and client side separately using TCP IP protocol TCP/IP, or the Transmission Control Protocol/Internet Protocol, is a suite of communication protocols used to interconnect network devices on the internet. TCP/IP can also be used as a communications protocol in a private computer network (an intranet or an extranet). TCP/IP can be used to provide remote login over the network, for interactive file transfer, to deliver email, to deliver webpages over the network and to remotely access a server host's file system.
TCP/IP Layer :

                                               Figure reference : www.guru99.com

socket programming interface provides the routines required for interprocess communication between applications, either on the local system or spread in a distributed, TCP/IP based network environment. Once a peer-to-peer connection is established, a socket descriptor is used to uniquely identify the connection.
The sockets are the endpoints of any communication channel. These are used to connect the server and client. Sockets are Bi-Directional. In this project, we setup sockets for each end and setup the chatroom system among different clients through the server. The server side has some ports to connect with client sockets. When a client tries to connect with the same port, then the connection will be established for the chat room. Every time a user connects to the server, a separate thread is created for that user and communication from server to client takes place along individual threads based on socket objects created for the sake of identity of each client.
There are basically two parts. The server side and the client side. When the server side script is running, it waits for any active connection request. When one connection is established, it can communicate with it. In this case we are using localhost. If machines are connected via LAN or same wifi hotspot, then we can use IP addresses to communicate. The server will display its IP. From the client side the IP address of the server to connect. A message sent to from server side act as broadcast message to all the clients.
To use a socket object in the program, we first start off by importing the socket library.The type parameter is set to Socket Stream, also the default which enables “sequenced, reliable, two-way, connection-based byte streams” over TCP protocol. This code makes a socket object, and binds it to localhost’s port 8080 as a socket server. When clients connect to this address with a socket connection, the server listens for data, and stores it in the “data” variable. When a client connects, the server calls accept() to accept, or complete, the connection. The client calls connect() to establish a connection to the server and initiate the three-way handshake. 
The handshake step is important since it ensures that each side of the connection is reachable in the network, in other words that the client can reach the server and vice-versa. It may be that only one host, client or server, can reach the other.
In the middle is the round-trip section, where data is exchanged between the client and server using calls to send() and recv().
At the bottom, the client and server close() their respective sockets.

Figure & theory reference

By :
Ashutosh Bardapurkar    (k-05)
Hrishikesh Deshpande    (k-16)
Archit Hiwrekar        (k-23)
Chinmay Kapkar    (k-33)

21 comments:

  1. Very informative piece of information

    ReplyDelete
  2. Nice work.. In depth and very informative.

    ReplyDelete
  3. Very good...... really liked the flow of information.....good work

    ReplyDelete
  4. Quite insightful, that too
    with crystal clear explanation

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. Interesting. Building server client relationship on the basis of IP and using for local networking.

    ReplyDelete