title: TCP Send multiple message without closing connection
body: <p>Hi guys i have build an app for android to get the GPS coordination and i want to send the data to my C# UWP server through TCP. As concept i have opened a socket and i want to send multiple messages without closing the socket.</p>
  
  <pre><code>socket = new java.net.Socket("192.168.2.10", 9999);
  printwriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
  printwriter.println("message1");
  printwriter.println("message2");
  printwriter.println("message3");
  printwriter.println("message4");
  printwriter.flush();
  </code></pre>
  
  <p>The problem is i only receive message1 or sometimes also messages2 on the server. The other message doesn't show on the server. I don't want to make new connection because i'm planning sending a lot of messages. If any of you know a solution would be appreciated.</p>
  
  <p>I'm currently using the server code for UWP in C# from <a href="https://msdn.microsoft.com/en-us/windows/uwp/networking/sockets" rel="nofollow">https://msdn.microsoft.com/en-us/windows/uwp/networking/sockets</a>.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.IO;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace Maps
  {
  
      class Connection
      {
          public async void Connectie()
          {
              try
              {
                  System.Diagnostics.Debug.WriteLine("Waiting for connection................");
  
                  //Create a StreamSocketListener to start listening for TCP connections.
                  Windows.Networking.Sockets.StreamSocketListener socketListener = new Windows.Networking.Sockets.StreamSocketListener();
  
                  //Hook up an event handler to call when connections are received.
                  socketListener.ConnectionReceived += SocketListener_ConnectionReceived;
  
                  //Start listening for incoming TCP connections on the specified port. You can specify any port that' s not currently in use.
                  await socketListener.BindServiceNameAsync("9999");
                  System.Diagnostics.Debug.WriteLine("Waiting for connection................");
              }
              catch (Exception e)
              {
                  //Handle exception.
              }
          }
  
          private async void SocketListener_ConnectionReceived(Windows.Networking.Sockets.StreamSocketListener sender,
      Windows.Networking.Sockets.StreamSocketListenerConnectionReceivedEventArgs args)
          {
              Stream inStream = args.Socket.InputStream.AsStreamForRead();
              StreamReader reader = new StreamReader(inStream);
                  reader = new StreamReader(args.Socket.InputStream.AsStreamForRead());
                  System.Diagnostics.Debug.WriteLine("connection................");
                  //Read line from the remote client.
                  string request = await reader.ReadLineAsync();
                  System.Diagnostics.Debug.WriteLine(request);                 
           }
      }
  }
  </code></pre>