简体   繁体   中英

Unable to read from the stream in java

I am using tcp socket for client server programming in java . After writing a message in the outputstream , I started to read the inputstream and I continues the reading till the inputstream returns -1(EOF). But its not returning -1, I got stucked. Please give your suggestions. Look at the code below.

int bytesRead = tcpSocket.readPacket(buffer);
while(bytesRead != -1) {
    builder.append(new String(buffer, 0, bytesRead));
    bytesRead = tcpSocket.readPacket(buffer);
}

If its a Socket then -1 would be returned when the connection is terminated (normally).

In your case, I would guess that there is no further data coming through but it is not returning -1 either.

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