Client server chat application

Post on 23-Jan-2017

436 views 9 download

transcript

CLIENT-SERVER CHAT APPLICATION

By

Piyush RawatPC Technology Pvt. Ltd.

Networking Basics

• Transmission Control Protocol (TCP)• Port• Socket

TCP• This protocol ensures that the data sent over two points in a

Network is received in the same order as it is sent. This is ensured by receiving acknowledgements from the receiver side for every packet sent.

PORTS• It is an address which determines the data origin and delivery

points over the Network. It is not a hardware device, but a logical construct that identifies a service or process.

SOCKET• A socket is one 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 is destined to be sent to.

Server Working• The server is based on multithreading concept, which runs a

separate thread for each client connected to it.• ServerSocket ss = new ServerSocket(3300); // a server socket is created try { while (true) { new Handler(ss.accept()).start(); } }

• The server is Broadcast type i.e. it allows the messages from one client to be sent to other client and vice-versa.

Client Working• The client requests connection to the server at a given port

and IP address.

• ip= getServerAddress(); //server address is received by user s = new Socket(ip, 3300); //new socket is created at particular IP

and port• Client is working on simple concept of creating new socket

and then sending and receiving messages • Request of clients are placed in a cue for server to resolve.

Classes and packages used• Server side:• javax.swingThis package is dealing in providing user interface, i.e. panels, scroll, text fields, etc.• java.ioThis package provides input/output facilities i.e. readers, writers, etc.• java.netThis package provides network related facilities like creating server sockets, accepting connections, etc.• java.utilThis package provides hashsets used for storing and updating objects of DataOutputStream and name of different client connected to server.

Continued..• Client side:• javax.swingHere also package is dealing in providing user interface, i.e. panels, scroll, text fields, buttons, etc.• java.ioThis package provides input/output facilities i.e. readers, writers, etc.• java.netThis package provides network related facilities like requesting server for connections, sending and receiving messages, etc.• java.utilThis package provides hashsets used for storing and updating objects of DataOutputStream and name of different client connected to server.

Final Implementation

Asking for IP address of server.

Asking for screen name

When user leaves

Scope• Can be used for private chat over LAN and over Internet*.• Can be further developed for file transfer.• Can be used for broadcasting notices in an organization.• Secure and reliable.• Can also be used as a backup if there is sudden breakdown of

internet connection.• Simple and effective with low memory and resource usage.• No dedicated server is required if the application is used for

Local Area Network(LAN) i.e. any PC can become server.• Basically this application can be for communication purpose

anywhere.*For over the internet connection a dedicated server with global IP will be required.

QUESTIONS ?

Thank you