public RpcTcpServerConnection(RpcTcpServerChannel channel, RpcTcpSocketConnection sock)
            : base(RpcConnectionMode.Unknown, RpcConnectionDirection.Server)
        {
            _channel = channel;
            _sock    = sock;

            _sock.RequestReceived += new Action <RpcTcpSocketConnection, int, RpcRequest>(
                (socket, seq, request) => {
                RpcTcpServerTransaction tx = new RpcTcpServerTransaction(_channel, this, socket, request, seq);
                OnTransactionCreated(tx);
            }
                );

            _sock.ResponseReceived += new Action <RpcTcpSocketConnection, int, RpcResponse>(
                (socket, seq, response) => {
                RpcTcpTransactionManager.EndTransaction(seq, response);
            }
                );

            _sock.Disconnected += new Action <RpcTcpSocketConnection>(
                (socket) => {
                OnDisconnected();
            }
                );
        }
        public RpcTcpDuplexConnection(RpcTcpClientChannel channel, TcpUri serverUri)
            : base(RpcConnectionMode.Duplex, RpcConnectionDirection.Client)
        {
            _serverUri = serverUri;

            _socket = new RpcTcpSocketConnection(RpcConnectionDirection.Client);
            _socket.Disconnected += new Action <RpcTcpSocketConnection>(
                (socket) => {
                OnDisconnected();
            }
                );

            _socket.RequestReceived += new Action <RpcTcpSocketConnection, int, RpcRequest>(
                (socket, seq, request) => {
                var tx = new RpcTcpServerTransaction(_channel, this, socket, request, seq);
                OnTransactionCreated(tx);
            }
                );

            _socket.ResponseReceived += new Action <RpcTcpSocketConnection, int, RpcResponse>(
                (socket, seq, response) => {
                RpcTcpTransactionManager.EndTransaction(seq, response);
            }
                );

            _channel = new RpcDuplexCallbackChannel("tcp", serverUri.ToString(), this, channel);
        }
        private void CreateConnection()
        {
            var sock = new RpcTcpSocketConnection(RpcConnectionDirection.Client);

            sock.Disconnected += new Action <RpcTcpSocketConnection>(
                (s) => {
                _parent.OnSubDisconnected();
            }
                );

            sock.RequestReceived += new Action <RpcTcpSocketConnection, int, RpcRequest>(
                (s, seq, request) => {
                // TODO
                // Not support this response
            }
                );

            sock.ResponseReceived += new Action <RpcTcpSocketConnection, int, RpcResponse>(
                (s, seq, response) => {
                RpcTcpTransactionManager.EndTransaction(seq, response);
            }
                );

            //
            // Auto Connect
            sock.BeginConnect(
                (TcpUri)_parent.RemoteUri,
                delegate(Exception ex) {
                if (ex != null)
                {
                    _retryBegin = DateTime.Now.AddSeconds(1);
                }
                else
                {
                    _parent.OnSubConnected();
                }
            },
                false
                );

            _sock = sock;
        }
Beispiel #4
0
 public void SendFailed(RpcErrorCode code, Exception ex)
 {
     Response = RpcResponse.Create(code, ex);
     RpcTcpTransactionManager.EndTransaction(Sequence, Response);
 }