Java simple client server program

前端 未结 3 1615
盖世英雄少女心
盖世英雄少女心 2021-01-26 00:50

I have written a simple java code to send a message from server to client and the client should display it respectively. The codes are.

Client.java

impor         


        
3条回答
  •  走了就别回头了
    2021-01-26 01:17

    Referring all your answers and searching a bit on google i have finally got the code running by making the following changes in Server Class.

    while (true) {
            Socket mysocket = server_socket.accept();
    
            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(mysocket.getOutputStream()));
            BufferedReader reader = new BufferedReader(new InputStreamReader(mysocket.getInputStream()));
            writer.write("Hello omkar \n");
            writer.flush();
            System.out.println("data sent");
        }
    

提交回复
热议问题