Exemplo n.º 1
0
 /// <summary>
 /// Constructs a new client.
 /// </summary>
 /// <param name="clientSocket"></param>
 public ClientWorker(Socket clientSocket)
 {
     _socket = clientSocket;
     LocalIPEndPoint = (IPEndPoint)clientSocket.RemoteEndPoint;
     ClientInfo = new ClientInformation(LocalIPEndPoint);
     _bwReceiver = new BackgroundWorker();
     _bwReceiver.DoWork += new DoWorkEventHandler(ReceivePacketFromClient);
     _bwReceiver.RunWorkerAsync();
 }
Exemplo n.º 2
0
 /// <summary>
 /// Performs the client work.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void BWConnect_DoWork(object sender, DoWorkEventArgs e)
 {
     try
     {
         _socket = new Socket(RemoteIPEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
         _socket.Connect(RemoteIPEndPoint);
         LocalIPEndPoint = (IPEndPoint)_socket.LocalEndPoint;
         ClientInfo = new ClientInformation(LocalIPEndPoint);
         e.Result = true;
         _bwReceiver = new BackgroundWorker();
         _bwReceiver.WorkerSupportsCancellation = true;
         _bwReceiver.DoWork += new DoWorkEventHandler(ReceivePacketFromServer);
         _bwReceiver.RunWorkerAsync();
         // Client is online...
     }
     catch
     {
         e.Result = false;
     }
 }