Пример #1
0
        // Constructor
        public Server(ServerForm form, StartStopServer del, ServerMessageReceived action,
                      ServerMessageResponse actionResponse, AddClientsToServer addClient,
                      RemoveClientsToServer removeClient, SetServerIPAddress serverIPDelegate)
        {
            // Create thread
            _serverThread      = new Thread(new ThreadStart(ServerMainThreadFunction));
            _serverThread.Name = "Server Main Thread";
            _serverThread.Start();

            // Create thread for UDP connection
            _threadSendToClient      = new Thread(new ThreadStart(ThreadReceiveResponse));
            _threadSendToClient.Name = "Server Thread Listener";
            _threadSendToClient.Start();

            _parentForm            = form;
            _endActionDelegate     = del;
            _messageReceivedAction = action;
            _messageResponseAction = actionResponse;
            _addClientDelegate     = addClient;
            _removeClientDelegate  = removeClient;
            _displayServerIP       = serverIPDelegate;

            // Get directory of job
            _directoryWork = Directory.GetCurrentDirectory();

            // Get local IP address
            _serverIPAddress = GetPublicIPAddress();

            _parentForm.Invoke(_displayServerIP, (object)_serverIPAddress);

            // How enable port forwarding
            NATUPNPLib.UPnPNATClass upnpnat = new NATUPNPLib.UPnPNATClass();
            _mappingsPort = upnpnat.StaticPortMappingCollection;

            GetLocalIPAddress();

            try
            {
                _mappingsPort.Add(_numberOfPortToListen, "TCP", _numberOfPortToListen, GetLocalIPAddress(), true, "CNC TCP Server");
            }
            catch (Exception excp)
            {
                MessageBox.Show(excp.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                // Send action
                _parentForm.Invoke(this._endActionDelegate, (object)false);
                return;
            }
        }
Пример #2
0
 private void manageToolStripMenuItem_Click(object sender, EventArgs e)
 {
     ServerForm server = new ServerForm(this);
 }