Beispiel #1
0
        private void PrivateMode_CheckedChanged(object sender, EventArgs e)
        {
            if (PrivateMode.Checked)
            {
                options.PrivateMode = true;

                //close threads
                if (UDPClientThread != null)
                {
                    if (UDPClientThread.IsAlive)
                    {
                        clientUDP.CloseThread(false);
                    }
                }
                if (TCPServerThread != null)
                {
                    if (TCPServerThread.IsAlive)
                    {
                        serverTCP.CloseThread(false);
                    }
                }
            }
            else
            {
                if (!Utilities.FindPort(ref portTCP))
                {
                    //there are no free ports so close the program
                    RealClose();
                }

                options.PrivateMode = false;

                serverTCP       = new ServerTCP(portTCP, options.DestPath, options.RicMode, this);
                TCPServerThread = new Thread(serverTCP.Execute);
                TCPServerThread.Start();

                //inizializzo clientUDP
                clientUDP       = new ClientUDP(options.Name, portTCP, this);
                UDPClientThread = new Thread(clientUDP.Execute);
                UDPClientThread.Start();
            }
            CheckBoxApparence(PrivateMode);
        }
Beispiel #2
0
        private void SettingsForm_Load(object sender, EventArgs e)
        {
            //set Pipe
            pipe = new NamedPipeServerStream("RibbitPipe", PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
            pipe.BeginWaitForConnection(PipeCallBack, pipe);

            //Initialize serverUDP
            serverUDP       = new ServerUDP(userList, sharingFormList, this);
            UDPServerThread = new Thread(serverUDP.Execute);
            UDPServerThread.Start();

            //if not private mode initialize serverTCP and clientUDP
            if (!options.PrivateMode)
            {
                //get a free port
                if (!Utilities.FindPort(ref portTCP))
                {
                    //there are no free ports so close the program
                    RealClose();
                }

                //Initialize serverTCP
                serverTCP       = new ServerTCP(portTCP, options.DestPath, options.RicMode, this);
                TCPServerThread = new Thread(serverTCP.Execute);
                TCPServerThread.Start();

                //Initialize clientUDP
                clientUDP       = new ClientUDP(options.Name, portTCP, this);
                UDPClientThread = new Thread(clientUDP.Execute);
                UDPClientThread.Start();
            }

            if (this.path != null)
            {
                this.LaunchSharingFormMethod(path);
            }
        }
Beispiel #3
0
        private void CloseThreadMethod(Thread thread, String lable)
        {
            if (thread.IsAlive)
            {
                thread.Join();

                //if the thread is contained in the threadlist remove it
                if (threadFormList.ContainsKey(thread))
                {
                    threadFormList.Remove(thread);
                }
            }

            if (lable == null)
            {
                return;
            }

            if (!realClose)
            {
                if (lable.Equals(Utilities.ServerUDP))
                {
                    //Initialize serverUDP
                    serverUDP       = new ServerUDP(userList, sharingFormList, this);
                    UDPServerThread = new Thread(serverUDP.Execute);
                    UDPServerThread.Start();
                }
                if (lable.Equals(Utilities.ServerTCP) && options.PrivateMode == false)
                {
                    //get a free port
                    if (!Utilities.FindPort(ref portTCP))
                    {
                        //there are no free ports so close the program
                        RealClose();
                    }

                    if (clientUDP != null)
                    {
                        clientUDP.PortTCP = portTCP;
                    }

                    //Initialize serverTCP
                    serverTCP       = new ServerTCP(portTCP, options.DestPath, options.RicMode, this);
                    TCPServerThread = new Thread(serverTCP.Execute);
                    TCPServerThread.Start();
                }
                if (lable.Equals(Utilities.CientUDP) && options.PrivateMode == false)
                {
                    //get a free port
                    if (!Utilities.FindPort(ref portTCP))
                    {
                        //there are no free ports so close the program
                        RealClose();
                    }

                    if (serverTCP != null)
                    {
                        serverTCP.PortTCP = portTCP;
                    }

                    //Initialize clientUDP
                    clientUDP       = new ClientUDP(options.Name, portTCP, this);
                    UDPClientThread = new Thread(clientUDP.Execute);
                    UDPClientThread.Start();
                }
            }
        }