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 }
public void Send(byte[] buffer) { if (!_connection.Connection.Connected) { return; } try { _connection.Write(buffer, 0, buffer.Length); } catch { //some error in the provider throw; } }
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 } }