Sending command from website to AppServer

May 14, 2014 at 11:43 AM
Edited May 19, 2014 at 9:07 AM

I recreated the telnet example. Now I want to use an website instead of telnet to send the command to the AppServer. But the following is not working:
IPEndPoint ipe = new IPEndPoint(IPAddress.Parse(""), 2012);
Socket socket = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);


if (socket.Connected)
      Byte[] bytesSent = (Byte[])System.Text.Encoding.ASCII.GetBytes(command);
      socket.Send(bytesSent, bytesSent.Length, 0);
Am I missing something??
May 14, 2014 at 2:48 PM
You didn't follow the protocol, the telnet protocol (command line) must have "\r\n" at the end of each message.
May 19, 2014 at 7:53 AM
Edited May 19, 2014 at 9:07 AM
the server receives the websites' requests.

Now I have another question:
Sometimes the request is not handled by the server. I made a test page that sends a request every second, counts the requests and sends the count to the server. The server also counts the received requests:
static int requests = 0;
static void appServer_NewRequestReceived(AppSession session, StringRequestInfo requestInfo)
      switch (requestInfo.Key.ToUpper())
          case ("ECHO"):
              Console.WriteLine("Server: " + requests + ", Webpage: " + requestInfo.Body);
After a couple of seconds the webpage has already send more requests than the server handled:
Server Console:
Server: 0, Webpage: 0
Server: 1, Webpage: 2
Server: 2, Webpage: 3
Server: 3, Webpage: 6
Server: 4, Webpage: 7
Server: 5, Webpage: 8
Server: 6, Webpage: 9
Server: 7, Webpage: 10

What could be the reason for this? Is the connection not ready for another request? It also happens when I change the interval to 5 seconds.

I would be very grateful for an answer. Thanks.
May 19, 2014 at 8:16 AM
The static variable requests is not thread safe.

Could you change it to Interlocked.Increment(xxx)?

I am not sure Console.WriteLine is thread safe, could you change it to logging?
May 19, 2014 at 9:05 AM
Edited May 19, 2014 at 9:10 AM
Thanks for the fast response.
I changed the code to
ConsoleLog.Info("Server: " + requests + ", Webpage: " + requestInfo.Body);
Interlocked.Increment(ref requests);
But request count still does not fit.
May 19, 2014 at 9:09 AM
Could you write a UnitTest project to demonstrate this issue, so that I can produce it in my site.
May 19, 2014 at 2:25 PM
I refactored the code to write a unit test and suddenly all requests are received.
I think I may have had request handler and command mixed together.
I am very embarassed! Thanks for your help!