示例#1
0
        protected override void OnReceive(CommunicationChannelTcp channel, object receivedObject)
        {
            try
            {
                if (receivedObject == null)
                {
                    return;
                }

                //search it in cache..
                TClient client = GetClientByChannel(channel);
                if (client != null)
                {
                    if (_receiveCallbacks.ContainsKey(receivedObject.GetType()))
                    {
                        _receiveCallbacks[receivedObject.GetType()](client, receivedObject);
                    }
                    else
                    {
                        Log.Error("Received unknown DTO type: {0}. Do not have a function to handle it, will be discarded",
                                  receivedObject.GetType().Name);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "An error occurred handling received object: {0}.", receivedObject != null ? receivedObject.ToString() : "null");
            }
        }
示例#2
0
        private void HandleAcceptTcpCLient(IAsyncResult ar)
        {
            TcpClient tmpClient = null;
            CommunicationChannelTcp tmpChannel = null;

            try
            {
                if (_connected)
                {
                    tmpClient  = _listener.EndAcceptTcpClient(ar);
                    tmpChannel = new CommunicationChannelTcp();

                    if (this.Formatter != null)
                    {
                        tmpChannel.Formatter = this.Formatter;
                    }

                    tmpChannel.Connected += HandleConnectedClient;
                    tmpChannel.Received  += HandleReceivedObject;
                    tmpChannel.Error     += HandleErrorOccurred;

                    tmpChannel.Open(tmpClient);

                    lock (((ICollection)_channels).SyncRoot)
                    {
                        _channels.Add(tmpChannel);
                    }
                }
            }
            catch (SocketException)
            {
                if (tmpClient != null)
                {
                    tmpClient.Close();
                }
                if (tmpChannel != null)
                {
                    tmpChannel.Close();
                }
            }
            catch (ObjectDisposedException)
            {
                if (tmpClient != null)
                {
                    tmpClient.Close();
                }
                if (tmpChannel != null)
                {
                    tmpChannel.Close();
                }
            }
            finally
            {
                if (_connected)
                {
                    _currentAsyncResult = _listener.BeginAcceptTcpClient(HandleAcceptTcpCLient, _listener);
                }
            }
        }
示例#3
0
        protected override void OnError(CommunicationChannelTcp source, Exception exception)
        {
            Log.Error(exception, "Error in communication with {0} at port {1}",
                      ((source.Remote != null) && (source.Remote.Address != null)) ? source.Remote.Address.ToString() : "[missing remote ip address]",
                      source.Local.Port.ToString());

            //inject the Exception in the receiving pipe to be handled, shall be handled by a dedicated AddErrorHandler<Exception>..
            Log.Error(exception, "An error occurred in transmission pipeline (receive,deserialize,handle,serialize,send).");
        }
示例#4
0
        protected override void OnConnect(CommunicationChannelTcp channel)
        {
            Log.Debug("Connection established with {0} at port {1}",
                      ((channel.Remote != null) && (channel.Remote.Address != null)) ? channel.Remote.Address.ToString() : "[missing remote ip address]",
                      channel.Local.Port.ToString());

            //create new client..
            Clients.Add(ClientFactory.GetClient(channel));
        }
示例#5
0
        }                                                                                              //sockexc

        protected virtual void OnReceive(CommunicationChannelTcp source, object receivedObject)
        {
        }
示例#6
0
        }                                                                           //commChan

        protected virtual void OnError(CommunicationChannelTcp source, Exception exception)
        {
        }                                                                                              //sockexc
示例#7
0
 protected virtual void OnConnect(CommunicationChannelTcp source)
 {
 }                                                                           //commChan