Java Socket Issue: Packets Are Merged At The Receiver Side

I'm having a socket problem. This problem occurs when I'm running the server and client on the same PC i.e. using "localhost" parameter. But problem is not seen when different PCs are being used. Client sends a file with these codes: output_local.write(buffer, 0, bytesRead); output_local.flush(); And after that in another method I'm sending a command with these: outputStream.write(string); outputStream.flush(); Server appends the command to the end of the file. So it thinks it hasn't received the command from the client yet. do you have an idea what might causing this problem? How can I solve the defect? below is the file receive method at the server: while (true) { try { bytesReceived = input.read(buffer); } catch (IOException ex) { Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex); System.out.println("exception occured"); break; } System.out.println("received:" + bytesReceived); try { /* Write to the file */ wr.write(buffer, 0, bytesReceived); } catch (IOException ex) { Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex); } total_byte = total_byte + bytesReceived; if (total_byte >= filesizeInt) { break; } }

以上就是Java Socket Issue: Packets Are Merged At The Receiver Side的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏