title: java client and C# server working with unicode
body: <p>I'm trying to build a tcp client and a server that will work with unicode. the server is in <code>C#</code> and looks like that:</p>
  
  <pre><code>    static void Main(string[] args)
      {
          // tcp setup
          TcpListener serverSocket = new TcpListener(8888);
          TcpClient clientSocket = default(TcpClient);
          serverSocket.Start();
  
          // waiting for client to connect
          clientSocket = serverSocket.AcceptTcpClient();
  
          // client comunication
          string resAscii = Recv(clientSocket);
          Send(clientSocket, "got from you: " + resAscii);
          string resUnicode = Recv(clientSocket);
          Send(clientSocket, "קיבלתי ממך: " + resUnicode);
          Console.ReadKey();
      }
  
      public static void Send(TcpClient client, string msg)
      {
          Byte[] sendtBytes = Encoding.Unicode.GetBytes(msg + "$");
          client.GetStream().Write(sendtBytes, 0, sendtBytes.Length);
          client.GetStream().Flush();
      }
      public static string Recv(TcpClient client)
      {
          byte[] recvBytes = new byte[65537];
          client.GetStream().Read(recvBytes, 0, (int)client.ReceiveBufferSize);
          string dataFromClient = System.Text.Encoding.Unicode.GetString(recvBytes);
          dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf('$'));
          return dataFromClient;
      }
  </code></pre>
  
  <p>and the client is in <code>java</code> (android):</p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      new Thread(new Runnable() {
          @Override
          public void run() {
              try {
                  Socket s = new Socket("192.168.0.102", 8888);
                  Send(s, "this is ascii");
                  String asciiString = Recv(s);
                  Send(s, "זה יוניקוד");
                  String unicodeString = Recv(s);
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
      }).start();
  }
  
  
  private String Recv(Socket s) throws IOException {
      byte[] b = new byte[10080];
      int read = s.getInputStream().read(b, 0, 1000);
      String ret = new String(b, "UTF16");
      ret = ret.substring(0, ret.indexOf('$'));
      return ret;
  }
  
  private void Send(Socket s, String msg) throws IOException {
      s.getOutputStream().write((msg + "$").getBytes("UTF16"));
  }
  </code></pre>
  
  <p>When I'm sending from the client to the server I get the message. But when the server sending to the client I get only Chinese letters:
  <a href="https://i.stack.imgur.com/I0S6A.png" rel="nofollow noreferrer">client (android) error</a>
  how can I fix it?</p>