title: Networking between Java Socket client and C++ (Boost based) server
body: <p>At work I'm designing a user interface for controlling groups of robots. The robots use UDP broadcasts to manage their movements with one another.</p>
  
  <p>The GUI needs to be able to communicate to the robots. To this end, an intermediary server is run. All robots listen to it (with UDP sensors), and all running GUIs connect to it (via TCP). It manages GUI &lt;-> Robot communications.</p>
  
  <p>However, the server is written with the C++ Boost library, and the GUI is written in Java, and some issues with the networking are occurring. I connect to the server with a socket fairly easily:</p>
  
  <pre><code>try {
      socket = new Socket(targetAddress, targetPort);
  } catch (IOException e) { e.printStackTrace(); }
  </code></pre>
  
  <p>The server registers the connection and everything looks good.</p>
  
  <p>However, when I try to send Strings:</p>
  
  <pre><code>try {
      stream.writeUTF(message);
      stream.flush();
  } catch (IOException e) { e.printStackTrace(); }
  </code></pre>
  
  <p><em>Note: I was initially using a PrintWriter to send strings one at a time (println()) but switched to DataOutputStream to see if it would help.</em></p>
  
  <p>We run into problems. Boost does not even register that I sent the message, even though Java successfully did. Additionally, when Strings are sent from the server, they are in an unrecognizable format.</p>
  
  <p>A bit of looking into the problem suggests that Boost automatically appends "header" text to all messages it sends, helping it to archive messages it receives. Since Java doesn't do this, it seems like this may be the cause. Is this correct? If so, how can we get around it?</p>
  
  <hr>
  
  <p>A few notes:</p>
  
  <ul>
  <li>Due to time constraints, switching to different libraries/languages on a large scale is not really an option. However, if there is a C++ TCP library that will allow the server to receive the messages I send, and we can easily integrate it, that would be <em>perfect</em>.</li>
  <li>The Java networking code works perfectly when connecting to a Java server. The difficulties seem to be happening in the Boost-Java interface.</li>
  <li>Unfortunately, neither myself or the other person working on this aspect of the project are that experienced in networking. :( My experience is with Java and GUI development, and the other person is an AI programmer / hardware specialist. Any and all help with this issue would be incredibly welcome.</li>
  </ul>