コード例 #1
0
        /// <summary>
        /// Translate and queue a Msg instance to send
        /// </summary>
        /// <param name="msg"></param>
        public void Send(Msg msg)
        {
            var s     = msg.Serialize();
            var bytes = Encoding.UTF8.GetBytes(s);

            Connection.Send(ByteMessageParser.CreateMessage(bytes));
        }
コード例 #2
0
 /// <summary>
 /// Creates a Connection Translator.
 /// </summary>
 /// <param name="connection">The Connection instance to use</param>
 /// <param name="onMsgRecieved">Called when a Msg instance is created from incoming byte arrays</param>
 /// <param name="generalExceptionAction">Called when an exception is thrown</param>
 /// <param name="onParseError">Called when a Msg cannot be parsed</param>
 /// <param name="connectionClosed">Called when the Connection closes</param>
 /// <param name="byteMsgRecieved">Called when bytes are received</param>
 public ConnectionManager(IComm connection, IReceiver onMsgRecieved, Action <ConnectionManager, Exception> generalExceptionAction, Action <ConnectionManager, Msg.DecodeResult, string> onParseError = null, Action <ConnectionManager> connectionClosed = null, Action <ConnectionManager, byte[]> byteMsgRecieved = null)
 {
     if (connection == null)
     {
         throw new ArgumentNullException();
     }
     Connection              = connection;
     Destination             = connection.Socket.RemoteEndPoint.ToString();
     _parser                 = new ByteMessageParser(PayloadCallback, ExceptionCallback);
     _onMsgRecieved          = onMsgRecieved;
     _generalExceptionAction = generalExceptionAction;
     _onParseError           = onParseError;
     _onMsgBytesRecieved     = byteMsgRecieved;
     _connectionClosed       = connectionClosed;
     Connection.Bind(ConnectionRecieve, OnConnectionClosed);
 }