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 f开发者_如何学Pythonrom 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
It could be because you are trying to do an in.readLine()
this requires that the server terminates the "receive" command which it is sending to the client with a newline.. "\n" or "\r\n" along
精彩评论