title: How to send a message from client to server using c# containg spaces
body: <p>I create the following code but there is one problem: I can't sent a large message from client to server which contains spaces.</p>
  
  <p>Here is my code for server </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Net;
  using System.Net.Sockets;
  
  
  namespace ServerApp
  {
      class Program
      {
          static void Main(string[] args)
          {
              Console.WriteLine("Starting: Creating Socket object");
              Socket listener = new Socket(AddressFamily.InterNetwork,
              SocketType.Stream,
              ProtocolType.Tcp);
              listener.Bind(new IPEndPoint(IPAddress.Any, 2112));
              listener.Listen(10);
              while (true)
              {
                  Console.WriteLine("Waiting for connection on port 2112");
                  Socket socket = listener.Accept();
                  string receivedValue = string.Empty;
                  while (true)
                  {
                      if (socket.Available &gt; 0)
                      {
                          byte[] receivedBytes = new byte[socket.ReceiveBufferSize];
                          int numBytes = socket.Receive(receivedBytes);
                          Console.WriteLine("Receiving...");
                          receivedValue += Encoding.ASCII.GetString(receivedBytes);
  
                          break;
  
                      }
                  }
                  Console.WriteLine("Received value: {0}", receivedValue);
                  Console.WriteLine("Enter ur Msg");
                  string replyValue = Console.ReadLine();
                  //string replyValue = "Message successfully received.";
                  byte[] replyMessage = Encoding.ASCII.GetBytes(replyValue);
                  socket.Send(replyMessage);
                  socket.Shutdown(SocketShutdown.Both);
                  socket.Close();
              }
              listener.Close();
          }
      }
  }
  </code></pre>
  
  <p>And here is my code for client</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Net;
  using System.Net.Sockets;
  
  namespace ClientApp
  {
      class Program
      {
          static void Main(string[] args)
          {
              byte[] receivedBytes = new byte[2048];
              //IPHostEntry ipHost = Dns.Resolve("192.168.1.55");
              IPHostEntry ipHost = Dns.Resolve("127.0.0.1");
              IPAddress ipAddress = ipHost.AddressList[0];
              //IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, 8000);
              IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, 2112);
              Console.WriteLine("Starting: Creating Socket object");
              Socket sender = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
              sender.Connect(ipEndPoint);
              Console.WriteLine("Successfully connected to {0}",sender.RemoteEndPoint);
              Console.WriteLine("Enter Client Message :");
              string sendingMessage = Console.ReadLine();
              //string sendingMessage = "Hello World Socket Test";
              Console.WriteLine("Creating message:{0}",sendingMessage);
              byte[] forwardMessage = Encoding.ASCII.GetBytes(sendingMessage + "[FINAL]");
              sender.Send(forwardMessage);
              int totalBytesReceived = sender.Receive(receivedBytes);
              Console.WriteLine("Message provided from server: {0}",Encoding.ASCII.GetString(receivedBytes,0, totalBytesReceived));
              sender.Shutdown(SocketShutdown.Both);
              sender.Close();
              Console.ReadLine();
          }
      }
  }
  </code></pre>
  
  <p>Please tell me the right way to do this.</p>
  
  <p>Thanks in advance for you suggestions</p>