0% found this document useful (0 votes)
3 views17 pages

Chat Server

Uploaded by

ayushi bhardwaj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views17 pages

Chat Server

Uploaded by

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

CHAT SERVER

Submitted to- Submitted by-


Ms. Pooja Varshney Ayushi Bhardwaj (88387)
(Assistant Professor) Nasreen Praveen (85548)
Table of Content
 What is Socket
 Socket Interface Types
 Row Socket
 Function of the Client-Server Chat Application
 The java.net package protocols
 Methods used in ServerSocket Class
 Client Server Diagram
 Future Work
 Conclusion
What is Socket?
 A socket is one endpoint of a two-way communication link between two
programs running on a network.

 It is one of the most fundamental technologies of computer network


programming. Sockets allow network software applications to communicate
using standard mechanisms built into network hardware and operating systems.

 A socket represents a single connection between exactly two pieces of


software (a so-called point-to-point connection). More than two pieces of
software can communicate with client/server or distributed systems by using
multiple sockets.
•Socket-based software usually runs on two separate computers on the
network, but sockets can also be used to communicate locally (inter-
process) on a single computer like our project.

• Sockets are bidirectional, meaning that either side of the connection is


capable of both sending and receiving data. Sometimes the one
application that initiates communication is termed the "client" and the
other application the "server".
Socket Interface Types:
Socket interfaces can be divided into three
categories:

1. Stream Socket
2. Datagram Socket
3. Raw Socket
Raw Socket:
•In computer networking, a raw socket is an internet socket that allows direct
sending and receiving of Internet Protocol packets without any protocol-
specific transport layer formatting.

•It bypasses the library's built-in support for standard protocols like TCP and
UDP. Raw sockets are used for custom low-level protocol development in
Client-Server communication.

•Raw sockets are used in security related applications.


Function of the Client-Server Chat
Application:
Basic principles:
•In a connection-oriented client-to-server model, the socket on the
server process waits for requests from a client.

•The client-to-server data exchange takes place when a client connects


to the server through a socket.

•A socket is bound to a port number so that the TCP layer can identify
the application that data is destined to be sent to. An endpoint is a
combination of an IP address and a port number.
• The server first establishes (binds) an address that clients can use
to find the server.

•When the address is established, the server waits for clients to


request a service to the server.

•The server performs the client's request and sends the reply back
to the client.
The java.net package supports two
common network protocols:
TCP: (Transmission Control Protocol): TCP is a connection-based
protocol
• reliable delivery
• in-order guaranteed
• connection-oriented
• bidirectionalA

UDP: (User Datagram Protocol): UDP is connectionless Protocol


• unreliable delivery
• no order guarantees
• no notion of "connection" - app indicates dest. for each
packet
• can send or receive
Methods used in ServerSocket Class:
The java.net.ServerSocket class is used by server application
to obtain a port and listen for client requests. The
ServerSocket class has four constructors:

•public ServerSocket (int port) throws IOException:


Attempts to create a server socket bound to the specified
port. An exception occurs if the port is already bound by
another application.

• public ServerSocket(int backlog) throws IOException:


Similar to the previous constructor, the backlog parameter
specifies how many Incoming clients to store in a wait queue.
•public ServerSocket(int address) throws IOException: Similar to
the previous constructor, the int address parameter specifies the
local IP address to bind to. The int address is used for servers that
may have multiple IP addresses, allowing the server to specify
which of its IP addresses to accept client requests on.

• public ServerSocket() throws IOException: Creates an unbound


server socket. When using this constructor, use the bind()
method when you are ready to bind the server socket. If the
ServerSocket constructor does not throw an exception, it means
that your application has successfully bound to the specified port
and is ready for client requests.
Client Server Diagram
socket.bind() − This method binds the address (hostname, port
number) to the socket.

socket.listen() − This method basically listens to the connections


made to the socket. It starts TCP listener. Backlog is an argument
of this method which specifies the maximum number of queued
connections. Its minimum value is 0 and maximum value is 5.

socket.accept() − This will accept TCP client connection. The pair


(conn, address) is the return value pair of this method. Here, conn
is a new socket object used to send and receive data on the
connection and address is the address bound to the socket. Before
using this method, the socket.bind() and socket.listen() method
must be used.
socket.connect(address) − this method actively intimate server connection or in
simple words this method connects the client to the server. The argument
address represents the address of the server.
socket.read()- This method will receive data.
socket.write()- This method will send data.
socket.close() − This method will close the socket.
Future Work
There is always a room for improvements in any software package,
however good and efficient it may be done. But the most important thing
should be flexible to accept further modification. Right now we are just
dealing with text communication. In future this software may be extended
to include features such as:
•Files transfer: this will enable the user to send files of different formats
to others via the chat application.
•Voice chat: this will enhance the application to a higher level where
communication will be possible via voice calling as in telephone.
.Video chat: this will further enhance the feature of calling into video
communication.
Conclusion
We Developed network applications in Java by using sockets, threads, and
Web services. These software is portable, efficient, and easily maintainable
for large number of clients. Our developed web-based chatting software is
unique in its features and more importantly easily customizable. The java.net
package provides a powerful and flexible set of classes for implementing
network applications. Typically, programs running on client machines make
requests to programs on a server Machine. These involve networking
services provided by the transport layer. The most widely used transport
protocols on the Internet are TCP (Transmission control Protocol) and UDP
(User Datagram Protocol). TCP is a connection-oriented protocol providing a
reliable flow of data between two computers. On the other hand, UDP is a
simpler message-based connectionless protocol which sends packets of data
known as datagrams from one computer to another with no guarantees of
arrival.
THANK YOU

You might also like