multithread client-server chat, using sockets

前端 未结 2 1376
离开以前
离开以前 2021-01-07 12:33

Server and client communicating with my own protocol which looks like XMPP. I should to realize chat application. So when one user write String it immedeatly should be sende

2条回答
  •  长情又很酷
    2021-01-07 13:08

    Try this,

    Do Not use BufferedReader() with PrintWriter..... PrintWriter is itself the Bridge between byte level socket data and character form.

    Eg:

    I am showing for a single client, use the while loop for n nos of clients

    ServerSocket s = new ServerSocket(4444);
    
    Socket incoming = s.accept();
    
    OutputStream output = s.getOutputStream();
    
    PrintWriter pw = new PrintWriter(output,true);
    

    System.out.println(pw.write(new Scanner(System.in).nextLine()));

提交回复
热议问题