I have multithreaded chatting java server which can handle number of clients (java). They can simultaneous talk with each other. They are connected through network socket. Besides their own conversation words, my purpose is to display the conversation words they do in web browser through web application. I am thinking about JavaScript but couldn't figure out how to implement javascript for web application because I will need object or data to pass to javascript side from server( java) side.
Following is the multithreaded server and this works fine with multiple clients.
public class GoodChatServer {
………
public static void main(String[] args) throws Exception {
System.out.println("The chat server is running.");
ServerSocket listener = new ServerSocket(PORT);
try {
….
}
} finally {
…..
}
}
private static class Handler extends Thread {
……….
this.socket = socket;
}
public void run() {
try {
in = new BufferedReader(new InputStreamReader(
socket.getInputStream()));
out = new PrintWriter(socket.getOutputStream(), true);
while (true) {
out.println("SUBMITNAME");
name = in.readLine();
if (name == null) {
..
}
synchronized (names) {
if (!names.contains(name)) {
names.add(name);
break;
}
DWRfor that.