コード例 #1
0
ファイル: ApiServer.cs プロジェクト: zpalmtree/cs-turtlecoin
        /// <summary>
        /// Starts listening for API requests
        /// </summary>
        /// <param name="Port">The port to listen for incoming requests on</param>
        public void Start(int Port)
        {
            // Store port
            this.Port = Port;

            // Start HTTP listener
            try
            {
                Listener = new HttpListener();
                Listener.Prefixes.Add($"http://+:{Port}/");
                Listener.Start();
            }
            catch
            {
                // TODO - better error handling
                Listener = new HttpListener();
                Listener.Prefixes.Add($"http://127.0.0.1:{Port}/");
                Listener.Start();
            }

            // Begin listener thread
            ListenerThread.Start();

            // Start our worker threads
            for (int i = 0; i < WorkerThreads.Length; i++)
            {
                WorkerThreads[i] = new Thread(AcceptContext);
                WorkerThreads[i].Start();
            }
        }
コード例 #2
0
 public virtual void startDaemon()
 {
     listenerThread        = new ListenerThread(this);
     listenerThread.Name   = "AutoDetectJpcsp - ListenerThread";
     listenerThread.Daemon = true;
     listenerThread.Start();
 }
コード例 #3
0
        public virtual void discover()
        {
            try
            {
                igd = new IGD();
                ListenerThread listener = new ListenerThread(this, igd);
                listener.Daemon = true;
                listener.Name   = "UPnP Discovery Listener";
                listener.Start();
                while (!listener.Ready)
                {
                    Utilities.sleep(100);
                }

                foreach (string device in deviceList)
                {
                    string discoveryRequest = string.Format("M-SEARCH * HTTP/1.1\r\nHOST: {0}:{1:D}\r\nST: {2}\r\nMAN: \"ssdp:discover\"\r\nMX: {3:D}\r\n\r\n", multicastIp, discoveryPort, device, discoveryTimeoutMillis / 1000);
                    IEnumerator <NetworkInterface> networkInterfaces = NetworkInterface.NetworkInterfaces;
                    while (networkInterfaces.MoveNext())
                    {
                        NetworkInterface networkInterface = networkInterfaces.Current;
                        if (networkInterface.Up && networkInterface.supportsMulticast())
                        {
                            for (IEnumerator <InetAddress> addresses = networkInterface.InetAddresses; addresses.MoveNext();)
                            {
                                InetAddress address = addresses.Current;
                                if (address is Inet4Address && !address.LoopbackAddress)
                                {
                                    MulticastSocket   socket        = new MulticastSocket(new InetSocketAddress(address, discoverySearchPort));
                                    InetSocketAddress socketAddress = new InetSocketAddress(multicastIp, discoveryPort);
                                    DatagramPacket    packet        = new DatagramPacket(discoveryRequest.GetBytes(), discoveryRequest.Length, socketAddress);
                                    socket.send(packet);
                                    socket.disconnect();
                                    socket.close();
                                }
                            }
                        }
                    }
                }

                for (int i = 0; i < discoveryTimeoutMillis / 10; i++)
                {
                    if (listener.Done)
                    {
                        break;
                    }
                    Utilities.sleep(10, 0);
                }

                listener.Done = true;
                while (!listener.Ready)
                {
                    Utilities.sleep(100);
                }
            }
            catch (IOException e)
            {
                Console.WriteLine("discover", e);
            }
        }
コード例 #4
0
ファイル: frmServer.cs プロジェクト: Corin101/ZavrsniRad
 private void BtnStart_Click(object sender, EventArgs e)
 {
     if (portNumber == 0 || (certificate == null && certificateName == null))
     {
         SetText("Port Number, certificate or certificate name must be filled!");
     }
     else
     {
         SetText("Starting Server!");
         if (certificateName == null)
         {
             server = new ServerBuilder(portNumber, certificate);
             DisableStart();
             ListenerThread = new Thread(new ThreadStart(server.StartListener));
         }
         else
         {
             server = new ServerBuilder(portNumber, certificateName);
             DisableStart();
             ListenerThread = new Thread(new ThreadStart(server.StartListener));
         }
         ListenerThread.Start();
     }
 }