Beispiel #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();
        }
Beispiel #2
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);
        }