title: Socket communicating between java and c# applications
body: <p>I have two applications, one written in Java and the other in C#. I am trying to send a string from the Java app to C# app. </p>
  
  <p>My java code for sending the string is as follows:</p>
  
  <pre><code>String response;
  try {
      DataOutputStream outToServer =
          new DataOutputStream(outGoingSocket.getOutputStream());
      BufferedReader inFromServer =
          new BufferedReader(new InputStreamReader(outGoingSocket.getInputStream()));
  
      outToServer.writeBytes(message + '\n');
      outToServer.flush();
  
      response = inFromServer.readLine();
  
      System.out.println("Received: " + response);        
  } catch (Exception ex) {
      System.err.println("Exception in incoming socket: " + ex.getMessage());
  }
  </code></pre>
  
  <p>My C# code for receiving the data is as follows:</p>
  
  <pre><code>Byte[] bytes = new Byte[1000];
  String data = null;
  try {
      Console.Write("Waiting for a connection... ");
      TcpClient client = incomingSocket.AcceptTcpClient();
      Console.WriteLine("Connected!");
  
      data = null;
      NetworkStream stream = client.GetStream();
  
      int i;
      while (true) {
          while ((i = stream.Read(bytes, 0, bytes.Length)) != 0) {
              data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
              Console.WriteLine("Received:", data);
              processReceivedMessage(data);
              ackSocket(stream, "OK");
          }
      }
  } catch (Exception ex) {
      Console.WriteLine("Exception: ", ex);
  }
  </code></pre>
  
  <p>I have a problem with receiving the data in the C# application. When I send the string "Data" in the Java app, and try to print the data received by the C# application using <code>Console.WriteLine("Received: {0}", data)</code>, the output is:</p>
  
  <pre><code>Received: D
  Received: ata
  </code></pre>
  
  <p>If I use <code>Console.WriteLine("Received: ", data)</code>, the output is:</p>
  
  <pre><code>Received: 
  Received: 
  </code></pre>
  
  <p>I want my C# application to receive the full string that is sent by the Java application. I tried to increase the buffer byte array size to 1000 but it doesn't help. I don't have experience using sockets, can someone show me what I did wrong?</p>