15

Click here to load reader

Chat server nitish nagar

Embed Size (px)

DESCRIPTION

Chat Server Java Based Project for multi-users. Easy to install.

Citation preview

Page 1: Chat server nitish nagar

CHAT SERVER BASED ON JAVA

Under the guidance of:

Mrs. Jaya Sharma,

Dept. of CS&E,

ASET.

Submitted by-

Nitish Nagar (A2305208383)

Rajkumar Mahalawat(A2305208440)

Raman Sethi (A2305208416)

B.Tech(CS&E) : 2008-12

Semester : 5th

Page 2: Chat server nitish nagar

CHAT SERVER

The “Chat Server” is a windows-based internet

chatting software system.

It is composed of two major subsystems: a Server

and a Client, which are independent processes that

can be executed on separate computers on a

network.

This includes allowing clients to login so they can be

identified by username and forwarding messages

from one client destined to another.

Examples of Chatting Applications : Gtalk, Yahoo

Messenger,Hotmail.

Su

mm

er P

roje

ct 2

01

0

Page 3: Chat server nitish nagar

SOCKETS AND JAVA SOCKET CLASSES

A socket is an endpoint of a two-way communication link between two programs running on the network.

A socket is bound to a port number so that the TCP layer can identify the application that data destined to be sent.

Java’s .net package provides two classes:

Socket – for implementing a client

ServerSocket – for implementing a server

There are four fundamental operations a socket

performs. These are:

Connect to a remote machine

Send data

Receive data

Close the connection 3

Su

mm

er P

roje

ct 2

01

0

Page 4: Chat server nitish nagar

Sockets provide an interface for programming networks at the transport layer.

A socket is a reliable connection for the transmission of data between two hosts.

A server (program) runs on a specific computer and

has a socket that is bound to a specific port. The

server waits and listens to the socket for a client to

make a connection request.

Socket-based communication is programming language independent.

That means, a socket program written in Java language can also communicate to a program written in Java or non-Java socket program.

4

Su

mm

er P

roje

ct 2

01

0

Page 5: Chat server nitish nagar

CLIENT SERVER PROGRAMMING

Client/server describes the relationship between twocomputer programs in which one program, the client,makes a service request from another program, theserver, which fulfills the request.

Clients and servers are connected by sockets.

5

Summer Project 2010

Server- waits

for requestsClient- sends a

request

Server- returns

a replay

Su

mm

er P

roje

ct 2

01

0

Page 6: Chat server nitish nagar

CLIENT/SERVER SOCKET INTERACTION:

TCP

6

wait for incoming

connection requestconnectionSocket =

welcomeSocket.accept()

create socket,port=x, for

incoming request:welcomeSocket =

ServerSocket()

create socket,connect to hostid, port=xclientSocket =

Socket()

close

connectionSocket

read reply from

connectionSocket

close

clientSocket

Server (running on hostid) Client

send request using

clientSocketread request from

connectionSocket

write reply to

connectionSocket

TCP connection setup

Su

mm

er P

roje

ct 2

01

0

Page 7: Chat server nitish nagar

SOCKET PROGRAMMING WITH TCP

7

Client must contact server

server process must first

be running

server must have created

socket (door) that

welcomes client’s contact

Client contacts server by:

creating client-local TCP

socket

specifying IP address, port

number of server process

When client creates socket:

client TCP establishes

connection to server TCP

When contacted by client,

server TCP creates new

socket for server process to

communicate with client

allows server to talk with

multiple clients

TCP provides reliable, in-order

transfer of bytes (“pipe”)

between client and server

application viewpoint

Su

mm

er P

roje

ct 2

01

0

Page 8: Chat server nitish nagar

Basic steps

1. Determine server location – IP address & port

2. Open network connection to server

3. Write data to server (request)

4. Read data from server (response)

5. Close network connection

6. Stop client

Basic steps

1. Determine server location - port (& IP address)

2. Create server to listen for connections

3. Open network connection to client

4. Read data from client (request)

5. Write data to client (response)

6. Close network connection to client

7. Stop server

Client Programming Server Programming

Su

mm

er P

roje

ct 2

01

0

Page 9: Chat server nitish nagar

THREADING

No more than one server socket can listen to a

particular port at one time.

Since a server may need to handle many

connections at once, server programs tend to be

heavily multi-threaded.

Generally the server socket passes off the actual

processing of connections to a separate thread.

There should be a loop which continually accepts

new connections.

Rather than handling the connection directly the

socket should be passed to a Thread object that

handles the connection.

Su

mm

er P

roje

ct 2

01

0

Page 10: Chat server nitish nagar

MULTITHREADED SERVER: FOR

SERVING MULTIPLE CLIENTS

CONCURRENTLY

10

Server

Threads

Server ProcessClient 1 Process

Client 2 Process

Internet

Su

mm

er P

roje

ct 2

01

0

Page 11: Chat server nitish nagar

Su

mm

er P

roje

ct 2

01

0

Page 12: Chat server nitish nagar

Su

mm

er P

roje

ct 2

01

0

Page 13: Chat server nitish nagar

APPLICATION

This also includes listing the usernames of the

clients that are currently logged in to facilitate

communication.

A “Chat Server” is a form of real-time Internet text

messaging (chat) or synchronous conferencing.

It is mainly designed for group communication in

discussion forums, called channels, but also

allows one-to-one communication via private

message as well as chat and data transfers

via Direct Client-to-Client.

Su

mm

er P

roje

ct 2

01

0

Page 14: Chat server nitish nagar

FUTUTRE SCOPE

Login session information: We can include a feature

in this application that will keep a record of the user’s

login session.

Offline messages: User can send messages to friends

even when they are offline.

File transferring and sharing: User can transfer one or

more files to other users. A file can also be shared

between two or more users.

Profile Database: The profile information of every user

can be stored at the server.

Login Timeout: This feature allows the user to be

logged in only for a specific time. After this time span

ends, the user is automatically logged out

Su

mm

er P

roje

ct 2

01

0

Page 15: Chat server nitish nagar

THANK YOU