Exemplo n.º 1
0
 public override void Connect(string host, int port)
 {
     Log.Info("Connect " + host + ":" + port);
     new Thread(() => {
         try {
             var ipAddress         = GetIpAddress(host);
             this._socket          = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
             IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, port);
             this._socket.Connect(ipEndPoint);
             _packetHandler = new TcpPacketHandler(OnPacket, OnError);
             OnConnected();
             new Thread(ReciveLoop)
             {
                 Name = "RecieveThread"
             }.Start();
             new Thread(SendLoop)
             {
                 Name = "SendThread"
             }.Start();
         } catch (Exception e) {
             OnConnectFail(e);
         }
     })
     {
         Name = "ConnectThread"
     }.Start();
 }
Exemplo n.º 2
0
 public TcpSocketWorker(TcpSocket tcpSocket, TcpPacketHandler tcpPacketHandler)
 {
     this.tcpSocket        = tcpSocket;
     this.tcpPacketHandler = tcpPacketHandler;
     this.Active           = false;
     this.isClosed         = false;
 }