title: How can I make my lua tcp server receive messages from a c# tcp client?
body: <p>so I am working on communication between c# and lua through a tcp server and it seems that the client connects to the server but the server doesn't receive a message.</p>
  
  <p>Here the code of the server in lua:</p>
  
  <pre class="lang-lua prettyprint-override"><code>-- load namespace
  local socket = require("socket")
  -- create a TCP socket and bind it to the local host, at any port
  local server = assert(socket.bind("*", 0))
  -- find out which port the OS chose for us
  local ip, port = server:getsockname()
  -- print a message informing what's up
  print("Please connect to localhost on port " .. port)
  print (ip)
  -- loop forever waiting for clients
  while 1 do
    -- wait for a connection from any client
    local client = server:accept()
    -- make sure we don't block waiting for this client's line
    client:settimeout(0)
    -- receive the line
    local line, err = client:receive()
    print (line)
    -- if there was no error, send it back to the client
    if not err then client:send(line .. "\n") end
    -- done with client, close the object
    --client:close()
  end
  </code></pre>
  
  <p>and here the code for the tcp client in c# :</p>
  
  <pre class="lang-c# prettyprint-override"><code>using System;
  using System.IO;
  using System.Net;
  using System.Text;
  using System.Net.Sockets;
  
  
  public class clnt
  {
  
      public static void Main()
      {
  
          try
          {
              TcpClient tcpclnt = new TcpClient();
              Console.WriteLine("Connecting.....");
  
              tcpclnt.Connect("localhost", 2296);
              // use the ipaddress as in the server program
  
              Console.WriteLine("Connected");
              Console.Write("Enter the string to be transmitted : ");
  
              String str = Console.ReadLine();
              Stream stm = tcpclnt.GetStream();
  
              ASCIIEncoding asen = new ASCIIEncoding();
              byte[] ba = asen.GetBytes(str);
              Console.WriteLine("Transmitting.....");
  
              stm.Write(ba, 0, ba.Length);
  
              byte[] bb = new byte[100];
              int k = stm.Read(bb, 0, 100);
  
              for (int i = 0; i &lt; k; i++)
                  Console.Write(Convert.ToChar(bb[i]));
  
              tcpclnt.Close();
          }
  
          catch (Exception e)
          {
              Console.WriteLine("Error..... " + e.StackTrace);
          }
      }
  
  }
  </code></pre>
  
  <p>I really hope you guys can help me with this.
  Thanks in advance,
  Simon</p>