Multiple client to server communication program in Java

前端 未结 3 1103
南旧
南旧 2020-12-14 21:33

I wrote a server-client communication program and it worked well.

Client module

import java.io.*;
import java.net.*;

class Client {
    public sta         


        
3条回答
  •  我在风中等你
    2020-12-14 22:22

    Well, when I do something like that, I implement a listener that manages the server side, so when a client (the client won't probably need changes) connects, the server launch one thread to work with that client.

    while (!stop)
                {
                    socket = serverSocket.accept();
                    HiloSocket hiloSocket = new HiloSocket(socket, this);
                    hiloSocket.start();
                }
    

    Of course, HiloSocket extends Thread and it has the logic behind to manage the client...

提交回复
热议问题