/// <summary>
        /// Closes and clears the socket, without causing exceptions.
        /// </summary>
        private void ResetSocket()
        {
            // Close the socket
            ClientSocket.Close();
            ClientSocket       = null;
            ClientSocketReader = null;

            // Indicate there is no socket connection
            ClientSocketState = SocketState.Closed;
        }
Exemplo n.º 2
0
 public TcpClientMatchingEngineConnector(IPEndPoint ipEndPoint, ISocketLog socketLog = null)
 {
     _clientTcpSocket = new ClientTcpSocket <MatchingEngineSerializer, TcpOrderSocketService>(
         socketLog,
         ipEndPoint,
         3000,
         () =>
     {
         _tcpOrderSocketService = new TcpOrderSocketService(_tasksManager);
         return(_tcpOrderSocketService);
     });
 }
Exemplo n.º 3
0
        public void TestConnectTimeOut(string Address)
        {
            var ipHostInfo   = Dns.GetHostAddresses(Address);
            var thePoint     = new IPEndPoint(ipHostInfo[0], int.Parse("80"));// this.theServiceSocket.LocalEndPoint;
            var theNewSocket = new ClientTcpSocket();

            theNewSocket.SendTimeout    = 1000;
            theNewSocket.ReceiveTimeout = 1000;
            theNewSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, true);
            theNewSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, true);
            theNewSocket.Connect(thePoint);
            var theServerSocket = theNewSocket.GetServerSocket();
            var theServer       = new ServerTcpSocket(theServerSocket);
        }
 private void buttonAbortiveClose_Click(object sender, EventArgs e)
 {
     try
     {
         ClientSocket.AbortiveClose();
         ClientSocket      = null;
         ClientSocketState = SocketState.Closed;
         textBoxLog.AppendText("Abortively closed socket" + Environment.NewLine);
     }
     catch (Exception ex)
     {
         ResetSocket();
         textBoxLog.AppendText("Error aborting socket: [" + ex.GetType().Name + "] " + ex.Message + Environment.NewLine);
     }
     finally
     {
         RefreshDisplay();
     }
 }
        private void buttonConnect_Click(object sender, EventArgs e)
        {
            try
            {
                // Read the IP address
                IPAddress serverIPAddress;
                if (!IPAddress.TryParse(textBoxIPAddress.Text, out serverIPAddress))
                {
                    MessageBox.Show("Invalid IP address: " + textBoxIPAddress.Text);
                    textBoxIPAddress.Focus();
                    return;
                }

                // Read the port number
                int port;
                if (!int.TryParse(textBoxPort.Text, out port))
                {
                    MessageBox.Show("Invalid port number: " + textBoxPort.Text);
                    textBoxPort.Focus();
                    return;
                }

                // Begin connecting to the remote IP
                ClientSocket                      = new ClientTcpSocket();
                ClientSocketReader                = new SocketPacketProtocol(ClientSocket);
                ClientSocket.ConnectCompleted    += ClientSocket_ConnectCompleted;
                ClientSocket.WriteCompleted      += ClientSocket_WriteCompleted;
                ClientSocket.ShutdownCompleted   += ClientSocket_ShutdownCompleted;
                ClientSocketReader.PacketArrived += ClientSocket_PacketArrived;
                ClientSocket.ConnectAsync(serverIPAddress, port);
                ClientSocketState = SocketState.Connecting;
                textBoxLog.AppendText("Connecting socket to " + (new IPEndPoint(serverIPAddress, port)).ToString() + Environment.NewLine);
            }
            catch (Exception ex)
            {
                ResetSocket();
                textBoxLog.AppendText("Error creating connecting socket: [" + ex.GetType().Name + "] " + ex.Message + Environment.NewLine);
            }
            finally
            {
                RefreshDisplay();
            }
        }