0% found this document useful (0 votes)
1 views

Final CN Mini Project (2)

The document is a mini project report on creating a chat server using socket programming as part of a Computer Networks course. It details the project's introduction, description, technical implementation, and includes screenshots of the code and working project. The report is submitted by a group of students and guided by a faculty member, certifying their completion of the project during the academic year 2022-23.

Uploaded by

Ro Hit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Final CN Mini Project (2)

The document is a mini project report on creating a chat server using socket programming as part of a Computer Networks course. It details the project's introduction, description, technical implementation, and includes screenshots of the code and working project. The report is submitted by a group of students and guided by a faculty member, certifying their completion of the project during the academic year 2022-23.

Uploaded by

Ro Hit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

CHAMELI DEVI GROUP OF INSTITUTIONS

INDORE (M.P.)

Chat Server using Socket Programming


Mini Project Report

CS602- Computer Networks

Submitted By:
Guided By:
Rishabh Diwan 0832CS201135
Prof. AnkitChakrawarti
Rishabh Verma 0832CS201136
Asst. Professor, CSE Dept.
Ritesh Pawar 0832CS201138
CDGI Indore
Rohit Rane 0832CS201139
Roman Birla 0832CS201140

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

CHAMELI DEVI GROUP OF INSTITUTIONS


2

INDORE (M.P.)

DEPARTMENT OFCOMPUTER SCIENCE & ENGINEERING

CERTIFICATE

This is to certify that Mr.Rishabh Diwan, Mr.Rishabh Verma, Mr.Ritesh Pawar, Mr.Rohit Rane, Mr.Roman
Birla with RGTU Enrollment No. 0832CS201135, 0832CS201136, 0832CS201138, 0832CS201139,
0832CS201140 have satisfactorily completed the Mini Project on“Chat Server using Socket Programming
” in “CS602-Computer Networks”, for B. Tech, VI Semester of the Computer Science & Engineering
during year 2022 – 23.

__________________________
Prof.Shailendra Kumar Mishra Signature of
Head of the Department Faculty In-charge
3

TABLE OF CONTENTS
CONTENTS PAGE NO.
Introduction of the Project 4-5
Description of the Project 6
Technical Details of the Project 7
Screenshot of the Code 8-13
Screenshot of working Project 14-16
References 17
4

Introduction of the Project

Sockets :-
A socket is one endpoint of a two way communication link between two programs running on the network. The
socket mechanism provides a means of inter-process communication (IPC) by establishing named contact
points between which the communication take place.

Like ‘Pipe’ is used to create pipes and sockets is created using ‘socket’ system call. The socket provides
bidirectional FIFO Communication facility over the network. A socket connecting to the network is created at
each end of the communication. Each socket has a specific address. This address is composed of an IP address
and a port number.

Server :-
Server is a piece of computer hardware or software (computer program) that provides functionality for other
programs or devices, called “clients”. This architecture is called the client–server model. Servers can provide
various functionalities, often called “services”, such as sharing data or resources among multiple clients, or
performing computation for a client. A single server can serve multiple clients, and a single client can use
multiple servers. A client process may run on the same device or may connect over a network to a server on a
different device.

Client :-
In computing, a client is a piece of computer hardware or software that accesses a service made available by a
server as part of the client–server model of computer networks. The server is often (but not always) on another
computer system, in which case the client accesses the service by way of a network.
5
6

Description of the Project


A chat server is a program that allows multiple users to communicate with each other in real-time over a
network. It enables users to exchange messages, share files, and engage in group discussions. Chat servers have
become increasingly popular with the rise of social networking and messaging apps, and they are commonly
used in online gaming communities, business settings, and other collaborative environments.

Socket programming is a low-level approach to establish a communication link between two applications over a
network. It allows developers to create custom network protocols and applications that operate at a lower level
than typical web applications. Socket programming enables developers to build chat servers that are scalable,
efficient, and customizable to specific needs.

To build a chat server using socket programming, the first step is to create a socket object that represents the
server endpoint. A socket is a software entity that represents an endpoint of a communication channel. It is an
abstraction layer between the application and the underlying network protocols. You can specify the transport
layer protocol such as TCP or UDP. TCP is a connection-oriented protocol that provides reliable, ordered, and
error-checked delivery of data packets. UDP is a connectionless protocol that provides faster, but less reliable,
delivery of data packets.

The next step is to bind the socket object to a specific network address and port number. This allows the server
to listen for incoming connections on that address and port. When a client wants to connect, it knows the
server's address and port number. A port number is a 16-bit unsigned integer that identifies a specific process on
a host machine. A server typically listens on a well-known port number, such as port 80 for HTTP or port 443
for HTTPS.

Once the server is listening for incoming connections, the next step is to set up a loop that continuously listens
for new connections from clients. When a client requests a connection, the server accepts the connection and
creates a new thread or process to handle that connection. A new thread or process is necessary to keep the
server responsive to other clients' requests. When a connection is established, the server should send a welcome
message to the client, indicating that the connection has been successfully established.

Once the connection has been established, the server starts receiving messages from the client. The server
should also broadcast these messages to all other connected clients, allowing multiple users to participate in a
group chat in real-time. When the server receives a message from a client, it should send it to all other clients.
This ensures that all clients receive messages in real-time and can respond accordingly.

To handle multiple clients simultaneously, the server may need to implement a mechanism to keep track of all
connected clients and their corresponding sockets. When the server receives a message from a client, it should
know which clients are connected and which sockets to use to send messages to those clients. One way to
accomplish this is to maintain a list of all connected clients and their sockets. When a new client connects, the
server adds it to the list. When a client disconnects, the server removes it from the list.

Finally, the server should have error handling code to handle exceptions such as network failures, client
disconnections, and other unforeseen events. The error handling code should ensure that the server does not
crash due to such errors. For example, if a client suddenly disconnects from the server, the server should
gracefully handle the disconnection and remove the client from the list of connected clients.
7

Technical Details of the Project


A chat server is a computer program that allows users to communicate with each other in real-time. It is
implemented using socket programming, which is a low-level networking technology used for communication
between computers over a network. In Java, socket programming is done using the java.net package, which
provides classes for creating network sockets and communication streams.

To create a chat server in Java using socket programming, follow these steps:

 Create a server socket: The first step is to create a server socket that will listen for incoming client
connections. This is done using the ServerSocket class in Java.

 Accept client connections: Once the server socket is created, it needs to accept incoming client
connections. This is done using the accept() method of the ServerSocket class, which returns a Socket
object representing the client connection.

 Create input and output streams: Once a client connection is accepted, create input and output streams to
read and write data to the client. This is done using the getInputStream() and getOutputStream()
methods of the Socket class.

 Handle client requests: After the input and output streams are created, the server needs to handle client
requests. In a chat server, this typically involves reading messages from one client and sending them to
all other connected clients.

 Close connections: Once the chat session is complete, the server needs to close the input and output
streams and the client socket connection. This is done using the close() method of the respective classes.
8

Screenshot of the Code

Screenshot – 1

Screenshot – 2
9

Screenshot – 3

Screenshot -4
10

Screenshot – 5

Screenshot - 6
11

Screenshot – 7
12

Screenshot – 8
13

Screenshot - 9
14

Screenshot of Working Project

Screenshot - 1

Screenshot - 2
15

Screenshot – 3

Screenshot – 4
16

Screenshot – 5
17

References

 Saloni Takawale1, Dr. Rupesh C. Jaiswal2, Multi-Client Server Communication Enhancement through
Intranet, ©IJRASET (UGC Approved Journal)

 “JAVA Networking and Socket programming”: www.tutorialspoint.com/ java/java_networking.html

 “LAN Messenger”: http://en.wikipedia.org/wiki/LAN_messenger (2012)


 Socket Programming –Dartmouth Computer Science http://www.cs.dartmouth.edu/~campbell/cs50/so
cketprogramming.html

 Ibrahim Muhammed Abba Socsit “Lan Chat Messenger (LCM) Using Java Programming WithVoip
”3rd IEEE International Conference on Research and Innovation in Information Systems – 2013
(ICRIIS’13)

 Kenneth L. Calvert and Michael J. Donahoo, TCP/IP Sockets in Java: Practical Guide for Programmers,
Second Edition, USA: Elsevier Inc.

 Umar, S and Justin, M.P. (2003). “Serviceoriented Network Socket”, ACM Publishers New York,1st
international conference on Mobile systems, applications and services.

 Handel, M and Herbsleb, J.D (2002) “What Is Chat Doing in the Workplace?”, ACM Publishers, New
York.

 Chandra, S. Y and Kumar, S. S (2009) An Introduction to CLIENT/SERVER COMPUTING, New Age


International Publishers, New Delhi

You might also like