Пример #1
0
        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();
            }
        }
Пример #2
0
        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
        }
Пример #3
0
        /// <inheritdoc />
        /// <summary>
        /// </summary>
        protected sealed override void Initialization()
        {
            Socketv4.Bind(new IPEndPoint(IPAddress.Any, Config.Port));

            //Socket v6.Bind(new IPEndPoint(IPAddress.IPv6Any, Config.Port));
            Socketv4.Listen(Config.PendingQueue);
            //Socket v6.Listen(Config.PendingQueue);
        }