wogle
wogle
2017-04-10 16:40

java severSocket 的问题

  • java

Socket socket=serverSocket.accept();

         //Create data input and output streams
         DataInputStream inputFromClient=new DataInputStream(socket.getInputStream());
         DataOutputStream outputToClient=new DataOutputStream(socket.getOutputStream());

         //receive radius from the client and output the result to client
         while(true){
                double radius=inputFromClient.readDouble();
                double area=radius*radius*Math.PI;

                outputToClient.writeDouble(area);

                jta.append("Radius received from client:"+radius+'\n');
                jta.append("Area found:"+area+'\n');
                 jta.append("currentThread()"+Thread.currentThread().toString()+Thread.currentThread().getState().toString());
                web_coummunication.Demo_web_coummunication.<init>()");
         }

在定义了serverSocket之后定义了一个死循环用于接收与发送信息;为甚么只有收到客户端信息后这个死循环的代码才会执行,而不是一直执行?

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答