public void Conncet(IPEndPoint endPoint) { socket.Connect(endPoint); SocketStream = new NetworkStream(socket); Receiver = new Thread(() => { try { while (true) { Utils.ReadFull(SocketStream, buffer, PacketFactory.PacketSize); IPacket header = PacketFactory.ParseHeader(buffer); chain.DoHandle(header); } } catch (Exception) { if (socket.Connected) { throw; } Dispose(); } }); Receiver.Start(); Status = (int)ClientSocketStatus.Handshaking; Utils.SendPacket(SocketStream, PacketFactory.CreateClientHello()); }
public void Connect(IPEndPoint remoteEndPoint) { socket.Connect(remoteEndPoint); networkStream = new NetworkStream(socket); Receiver = new Thread(() => { try { while (true) { Utils.ReadFull(networkStream, buffer, PacketFactory.PacketSize); IPacket header = PacketFactory.ParseHeader(buffer); chain.DoHandle(header); } } catch (SocketException) { if (socket.Connected) { throw; } } catch (IOException e) { if (e.InnerException != null && e.InnerException.GetType() != typeof(SocketException) && !socket.Connected) { return; } } finally { Dispose(); } }); Receiver.Name = "IBLVM Client Receiver"; Receiver.Start(); Status = (int)ClientSocketStatus.Handshaking; Utils.SendPacket(SocketStream, PacketFactory.CreateClientHello()); }