I have created a server in java which accepts client connections. But I am able to only connect one client
class Server extends Thread{
private void startServer() {
try{
ss=new ServerSocket(3000);
s=ss.accept();
DataRead d1=new DataRead();
d1.t.start();
}catch(Exception er){
er.printStackTrace();
}
}
}
You only ever accept one socket. In your
jButton1ActionPerformedyou haveBut that is only invoked once, when you click the jButton1 button. You need to keep calling
accept()to if you want to have multiple clients able to connect.Also, keep in mind that each call to
accept()will block until a client connects and then return a new socket, representing that connection. So if you want to support multiple client, you shouldn’t have yourSocketas a global variable, it should instead be included in the constructor of yourDataReadclass, so each reader operates on a unique socket/connection/client.