Ejemplo n.º 1
0
 public override void OnAcceptConnection(ChoConnectionState state)
 {
     _receivedStr = "";
     if (!state.Write(Encoding.UTF8.GetBytes(
                          "Hello World!\r\n"), 0, 14))
     {
         state.EndConnection();
     }
     //if write fails... then close connection
 }
Ejemplo n.º 2
0
 public override void OnReceiveData(ChoConnectionState state)
 {
     byte[] buffer = new byte[1024];
     while (state.AvailableData > 0)
     {
         int readBytes = state.Read(buffer, 0, 1024);
         if (readBytes > 0)
         {
             _receivedStr +=
                 Encoding.UTF8.GetString(buffer, 0, readBytes);
             if (_receivedStr.IndexOf("<EOF>") >= 0)
             {
                 state.Write(Encoding.UTF8.GetBytes(_receivedStr), 0,
                             _receivedStr.Length);
                 _receivedStr = "";
             }
         }
         else
         {
             state.EndConnection();
         }
         //If read fails then close connection
     }
 }