Beispiel #1
0
        public void RegisterTcpClientHolder(Devcat.Core.Net.TcpClient tcpClient)
        {
            tcpClient.ConnectionSucceed += delegate(object sender, EventArgs evt)
            {
                string text = string.Format("[Peer {0}:{1}]", tcpClient.LocalEndPoint.Address.ToString(), tcpClient.LocalEndPoint.Port.ToString());
                Log <DSService> .Logger.WarnFormat("{0} Connect ", text);

                object typeConverter = DSService.Instance.MessageHandlerFactory.GetTypeConverter();
                tcpClient.Transmit(SerializeWriter.ToBinary(typeConverter));
                DSHostConnectionQuery value = new DSHostConnectionQuery();
                tcpClient.Transmit(SerializeWriter.ToBinary <DSHostConnectionQuery>(value));
                TcpClientHolder tcpClientHolder = new TcpClientHolder();
                tcpClientHolder.BindTcpClient(tcpClient);
                tcpClientHolder.TimeoutShedID = Scheduler.Schedule(this.Thread, Job.Create <TcpClientHolder>(new Action <TcpClientHolder>(this.UnregisterTcpClientHolder), tcpClientHolder), 30000);
                this.TcpClientHolders.Add(tcpClientHolder);
            };
            tcpClient.ExceptionOccur += delegate(object sender, EventArgs <Exception> evt)
            {
                string text = string.Format("[Peer {0}:{1}]", tcpClient.LocalEndPoint.Address.ToString(), tcpClient.LocalEndPoint.Port.ToString());
                Log <DSService> .Logger.ErrorFormat("{0} ExceptionOccur", text);

                DSLog.AddLog(-1, null, -1L, -1, "ExceptionOccur", text);
            };
            tcpClient.ConnectionFail += delegate(object sender, EventArgs <Exception> evt)
            {
                string text = string.Format("[Peer {0}:{1}]", tcpClient.LocalEndPoint.Address.ToString(), tcpClient.LocalEndPoint.Port.ToString());
                Log <DSService> .Logger.ErrorFormat("{0} ConnectionFail", text);

                DSLog.AddLog(-1, null, -1L, -1, "ConnectionFail", text);
            };
        }
Beispiel #2
0
 public void UnregisterTcpClientHolder(TcpClientHolder clientHolder)
 {
     if (!clientHolder.HasTransfered)
     {
         clientHolder.DisconnectTcpClient();
     }
     this.TcpClientHolders.Remove(clientHolder);
 }