Пример #1
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);
            }
        }
Пример #2
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();
                }
            }
        }