Esempio n. 1
0
        private void buttonStart_Click(object sender, EventArgs e)
        {
            // Read the port number
            int port;

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

            try
            {
                // Define the socket, bind to the port, and start accepting connections
                ListeningSocket = new ServerTcpSocket();
                ListeningSocket.AcceptCompleted += ListeningSocket_AcceptCompleted;
                ListeningSocket.Bind(port);
                ListeningSocket.AcceptAsync();

                textBoxLog.AppendText("Listening on port " + port.ToString() + Environment.NewLine);
            }
            catch (Exception ex)
            {
                ResetListeningSocket();
                textBoxLog.AppendText("Error creating listening socket on port " + port.ToString() + ": [" + ex.GetType().Name + "] " + ex.Message + Environment.NewLine);
            }
            RefreshDisplay();
        }
Esempio n. 2
0
        /// <summary>
        /// Closes and clears the listening socket and all connected sockets, without causing exceptions.
        /// </summary>
        private void ResetListeningSocket()
        {
            // Close all child sockets
            foreach (KeyValuePair <ServerChildTcpSocket, ChildSocketContext> socket in ChildSockets)
            {
                socket.Key.Close();
            }
            ChildSockets.Clear();

            // Close the listening socket
            ListeningSocket.Close();
            ListeningSocket = null;
        }
Esempio 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);
        }
Esempio n. 4
0
        public GameSocketManager Start()
        {
            _actionThread = new ActionThread
            {
                Name = "IHI-GameSocketThread"
            };

            _actionThread.Start();
            _actionThread.Do(() =>
            {
                _listeningSocket = new ServerTcpSocket();
                _listeningSocket.AcceptCompleted += IncomingConnectedAccepted;
                _listeningSocket.Bind(Address, Port);
                _listeningSocket.AcceptAsync();
            });

            return(this);
        }