public override void Operation() { try { // Connect to the remote endpoint. Socketv4.BeginConnect(new IPEndPoint(IPAddress.Loopback, Config.Port), ConnectCallback, Socketv4); _connectDone.WaitOne(); // Send test data to the remote device. Send(Socketv4, Message); _sendDone.WaitOne(); // Receive the response from the remote device. Receive(Socketv4); _receiveDone.WaitOne(); // Write the response to the console. //Console.WriteLine("Response received : {0}", response); // Release the socket. Socketv4.Shutdown(SocketShutdown.Both); Socketv4.Close(); } catch (Exception e) { ErrorUtil.WriteError(e).GetAwaiter().GetResult(); } }
public override void Operation() { while (true) { try { while (true) { _allDone.Reset(); // Start an asynchronous socket to listen for connections. Socketv4.BeginAccept( AcceptCallback, Socketv4); // Wait until a connection is made before continuing. _allDone.WaitOne(); } } catch (Exception e) { Message.Body = e; ErrorUtil.WriteError(e).GetAwaiter().GetResult(); } Socketv4.Close(); } // ReSharper disable once FunctionNeverReturns }