简体   繁体   中英

TCP connection Socket.getInputStream()

I created an application which establishes connection with the given port and transport data either ways. But I am having issues in reading the data from the server.

try{

    Socket skt = new Socket(127.98.68.11, 1111); // connecting to this to get data

    String message = "some test message";

    if(option.equalsIgnoreCase("send")){

         OutputStream outToServer = skt.getOutputStream();
          outToServer.write(message); // this is working, message stored on server-side
    }else if(option.equalsIgnoreCase("receive")){
          BufferedReader in = new BufferedReader (new InputStreamReader(sit.getInputStream()));

          String fromServer = in.readLine();
          System.Out.Println(fromServer);
    }

}catch(IOException io){
   io.printStackTrace();
}

In this program everything is working as expected. except in.readline().

I tried running this program in debugging mode, and the by the time compiler reaches this command. is was doing nothing and i can't see the cursor also

可能是因为您尝试执行in.readLine()这要求服务器使用换行符终止发送给客户端的“接收”命令。“ \\ n”或“ \\ r \\ n”

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM