The design and structure and helpful tips when writing a chat module in java© BrainMass Inc. brainmass.com February 24, 2021, 2:07 pm ad1c9bdddf
The Basic Steps Required to write a chat program in java
How does a chat program work ??
A chat program has two main parts- a client program, and a server program
The client program runs on the local machine of the person/people who is/are chatting
The server program runs on another machine, to which each client is connected.
Say three people (A,B,C) are chatting online.
If A wants to send a message to B and C, he sends the message to the server,and the server in turn sends the message to B and C.
How do the client and server programs communicate with each other ??
There are a number of ways two remote computers can communicate with each other, a simple way is through TCP Sockets
A socket is a permanent connection between two computers,(similar to a telephone call)
This connection will persist until either one or both computers explicitely disconnect it(exactly like in a telephone call).
How do you make a socket connection from the client to the server?
This can be achieved with the use of just two simple classes in Java - Socket and ServerSocket (located in the java.net
Detailed explanation of each module:
The client program will first establish a socket with the server.
Once it establishes a socket-
1. It will send data to the server through the socket.
2. and it will CONSTANTLY "look out for" or listen to any message which the server would send it
This constant listening for any messages ...
Ideas for writing a chat module in java are presented.