title: Send message through Socket Outputstream from Swift Client to Java Server
body: <p>As the title says, I'm having some problems connecting my Swift Client to a Java Server by using only native libraries.</p>
  <p>Right now I have a Java(client) to Java(server) connection, which works flawlessly, and a Swift(client) to Java(server) connection. My Swift client does connect to the Java server (it shows on the console), but the readFully of my server hangs -  the only thing I see is the enormous message length on the console and that's pretty much it.</p>
  <p>Swift Code (send):</p>
  <pre><code>func send(message: String) {
    let data = &quot;msg:\(message)&quot;.data(using: .utf8)!
  
      data.withUnsafeBytes {
      guard let pointer = $0.baseAddress?.assumingMemoryBound(to: UInt8.self) else {
        print(&quot;Error joining chat&quot;)
        return
      }
      out!.write(pointer, maxLength: data.count)
    }
  }
  </code></pre>
  <p>Java Server (read):</p>
  <pre><code>int lenght = in.readInt();
  System.out.println(&quot;Message: &quot; + lenght);
  if(length&gt;0){
   byte[] message = new byte[length];
   in.readFully(message), 0, message.length); //This is where the problem is
  }
  </code></pre>
  <p>So, basically the Java server hangs on the readFully method. Any ideas why that is? Whether I send a simple String or a Byte array, it always hangs, and for some reason the length is extremely big. Can someone help me understand what I'm doing wrong because I've around this for days and still didn't understand it (still pretty new to Swift).</p>
  <p>Thank you very much!</p>