Java client and a C++ server send and receive via TCP Socket

后端 未结 3 515
渐次进展
渐次进展 2021-01-05 17:09

I have a C++ server and two clients (ruby and java). Everything is running on a 64-bit linux-machine (java 1.7.0_17) The ruby client is fully working, but the java version m

相关标签:
3条回答
  • 2021-01-05 17:25
    while ((recv_count = recv(SocketFD, buffer, sizeof(buffer) - 1, 0)) > 0) {
          if (recv_count == -1) {
    

    I don't know what your problem is but this code is certainly nonsense. It is impossible for the inner test ever to succeed.

    0 讨论(0)
  • 2021-01-05 17:38

    PrintWriter buffer (when autoflush is true) is only flushed by calling println or printf. Calling print may not flush the buffer (Javadoc). Try calling println or use a OutputStreamWriter directly and flush(). Be aware of using the right charset (You can set it up in OutputStreamWriter constructor).

    0 讨论(0)
  • 2021-01-05 17:43

    Close the stream respectively flush it in a way like this:

    DataOutputStream dataOut = new DataOutputStream(socket.getOutputStream());
    dataOut.writeUTF(s);
    dataOut.flush();
    
    0 讨论(0)
提交回复
热议问题