简体   繁体   English

TCP连接Socket.getInputStream()

[英]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(). 除了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”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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