示例#1
0
        private void M_socket_OnSocketStatusChangedEvent(object arg1, SocketStatusChangedArgs <ProtocolPackageBase> arg2)
        {
            Console.WriteLine("TCP-Client连接状态改变:" + arg2.Status);


            //展示处理TCP的断线重连
            if (m_socket.NetProtocolType == EnumNetworkType.TCP)
            {
                if (arg2.Status == EnumNetworkStatus.Shutdown && !m_socket.Disposed)
                {
                    new Thread(new ThreadStart(() =>
                    {
                        try
                        {
                            //休眠5s,避免不断重连,
                            Thread.Sleep(5000);
                            m_socket.Create();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("TCP-Client重连失败");
                        }
                    })).Start();
                }
            }
        }
示例#2
0
 public void Create(IPEndPoint localEP)
 {
     m_socket.Create(localEP, null);
 }