Exemple #1
0
        public Form1()
        {
            _form_slave       = this;//not after,because is used by other method called in constructor
            passwordValidator = new StringValidator(
                CommonClasses.DefaultSettings.MinPasswordLength,
                CommonClasses.DefaultSettings.MaxPasswordLength);

            InitializeComponent();


            //this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
            //notifyIcon1.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);


            socket = new SlaveSocket(); //Server in ascolto su localhost ad una porta di default
            socket.setForm(this);
            // dispatcher = new InputDispatcher();

            /*dispatcherThread = new Thread(
             *  new ThreadStart(dispatcherThreadFunc));*/

            //socketThreadFunc();
            socketThread = new Thread(socketThreadFunc);
            // socketThread.IsBackground = true;
            // dispatcherThread.Start();

            //MasterAcceptFunction(ns);
            socketThread.Start();
        }
Exemple #2
0
        //Effettua la modifica della porta generando un nuovo socket in ascolto, dopo aver chiuso il precedente
        //E' necessario richiamare WaitForMasterConnection() per iniziare di nuovo l'ascolto sulla porta specificata
        public void ChangeListeningPort(Int32 newPort)
        {
            try
            {
                Int32 oldPort = ((IPEndPoint)socket.listener.LocalEndpoint).Port;

                if (newPort != oldPort)
                {
                    //string address = ((IPEndPoint)li.LocalEndpoint).Address.ToString();
                    string address = "127.0.0.1";

                    socket.listener.Server.Close();
                    //socket.listener.Stop();
                    socketThread.Abort();

                    try
                    {
                        isConnectedMaster = false;
                    }
                    catch (Exception exp) { }

                    socket = new SlaveSocket(newPort);
                    socket.setForm(this);
                    socketThread = new Thread(socketThreadFunc);
                    socketThread.IsBackground = true;
                    socketThread.Start();
                }
            }
            catch (ArgumentNullException)
            {
                Console.WriteLine("No form available to display infos");
            }
            catch (SocketException e)
            {
                Console.WriteLine("SocketException: {0}", e);
            }
        }