示例#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
 }
示例#2
0
        public void Send(byte[] buffer)
        {
            if (!_connection.Connection.Connected)
            {
                return;
            }

            try
            {
                _connection.Write(buffer, 0, buffer.Length);
            }
            catch
            {
                //some error in the provider
                throw;
            }
        }
示例#3
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
     }
 }