title: Is there a difference in Java's writeInt when executed on Windows vs an Intel based Mac
body: <p>I currently writing a Java TCP server to handle the communication with a client (which I didn't write).  When the server, hosted on windows, responds to the client with the number of records received the client doesn't read the integer correctly, and instead reads it as an empty packet.  When the same server code, hosted on my Mac, responds to the client with the number of records received the client reads the packet and responds correctly.  Through my research I haven't found an explanation that seems to solve the issue.  I have tried reversing the bytes (Integer.reverseBytes) before calling the writeInt method and that didn't seem to resolve the issue.  Any ideas are appreciated.</p>
  
  <p>Brian</p>
  
  <p>After comparing the pcap files there are no obvious differences in how they are sent.  The first byte is sent followed by the last 3.  Both systems send the correct number of records.</p>
  
  <p>Yes I'm referring to the DataOutputStream.writeInt() method. //Code added </p>
  
  <pre><code> public void run() {
  try {
          InputStream in = socket.getInputStream();
          DataOutputStream datOut = new DataOutputStream(socket.getOutputStream());
  
          datOut.writeByte(1); //sends correctly and read correctly by client
          datOut.flush();
  
          //below is used to read bytes to determine length of message
  
          int bytesRead=0;
          int bytesToRead=25;
          byte[] input = new byte[bytesToRead];
          while (bytesRead &lt; bytesToRead) {
              int result = in.read(input, bytesRead, bytesToRead - bytesRead);
              if (result == -1) break;
              bytesRead += result;
         }
          try {
                  inputLine = getHexString(input);
                  String hexLength = inputLine.substring(46, 50);
                  System.out.println("hexLength: " + hexLength);
                  System.out.println(inputLine);
  
                  //used to read entire sent message
  
                  bytesRead = 0;
                  bytesToRead = Integer.parseInt(hexLength, 16);
                  System.out.println("bytes to read " + bytesToRead);
                  byte[] dataInput = new byte[bytesToRead];
                  while (bytesRead &lt; bytesToRead) {
                      int result = in.read(dataInput, bytesRead, bytesToRead - bytesRead);
                      if (result == -1) break;
                      bytesRead += result;
                  }
  
                  String data = getHexString(dataInput);
                  System.out.println(data);
  
                  //Sends received data to class to process
  
                  ProcessTel dataValues= new ProcessTel(data);
                  String[] dataArray = new String[10];
                  dataArray = dataValues.dataArray();
  
                  //assigns returned number of records to be written to client
  
                  int towrite = Integer.parseInt(dataArray[0].trim());
  
                  //Same write method on Windows &amp; Mac...works on Mac but not Windows
  
                  datOut.writeInt(towrite);
  
                  System.out.println("Returned number of records: " + Integer.parseInt(dataArray[0].trim()) );
                  datOut.flush();
              } catch (Exception ex) {
                  Logger.getLogger(ServerThread.class.getName()).log(Level.SEVERE, null, ex);
              }
      datOut.close();
      in.close();
      socket.close();
  
  } catch (IOException e) {
      e.printStackTrace();
  }
  
  }
  </code></pre>