public virtual void startDaemon() { listenerThread = new ListenerThread(this); listenerThread.Name = "AutoDetectJpcsp - ListenerThread"; listenerThread.Daemon = true; listenerThread.Start(); }
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); } }
/// <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(); } }
/// <summary> /// Stop the listener thread /// </summary> public void Stop() { // Request the listener thread to stop StopRequested = true; // Wait for termination ListenerThread.Join(1000); }
public virtual void Sleep() { if (ListenerThread != null) { ListenerThread.Abort(); ListenerThread = null; } }
public void Dispose() { if (this.listener != null) { this.listener.Dispose(); this.listener = null; } this.CurrentWindow = null; }
public SocketLock(ListenerThread evaluator) { Monitor.Enter(evaluator.socketLock); #if DEBUG Debug.Assert(evaluator.socketLockedThread == null); evaluator.socketLockedThread = Thread.CurrentThread; #endif this.evaluator = evaluator; }
/// <summary> /// Stops the server and ends all associated threads /// </summary> public void Stop() { StopEvent.Set(); ListenerThread.Join(); foreach (Thread worker in WorkerThreads) { worker.Join(); } Listener.Stop(); }
/// <summary> /// Stop the listener thread /// </summary> public void Stop() { // Resume copying to allow buffers to flush ResumeCopying(); // Request the listener thread to stop StopRequested = true; // Wait for termination ListenerThread.Join(1000); }
static void Main(string[] args) { ListenerThread listener = new ListenerThread(); Thread listenerThread = new Thread(listener.Listen); listenerThread.Start(); Console.WriteLine("Press enter to exit application."); Console.ReadLine(); listener.Stop(); Server.MovieManager.Instance.Shutdown(); }
/// <summary> /// Stops the Proxy Server, removes the Windows proxy settings, and cleans up the thread. /// </summary> public void Stop() { // remove the proxy this.SetProxy(false); //stop listening for incoming connections Listener.Stop(); //wait for server to finish processing current connections... ListenerThread.Abort(); ListenerThread.Join(); }
private void Connect() { if (this.listener != null) { this.listener.Disconnect(); this.listener.Dispose(); this.listener = null; } if (!this.EnsureNodeInstalled()) { return; } CreateConnection(out var socket, out var port); var scriptPath = "\"" + Path.Combine( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "visualstudio_nodejs_repl.js" ) + "\""; var psi = new ProcessStartInfo(this.NodeExePath, scriptPath + " " + port) { CreateNoWindow = true, UseShellExecute = false, RedirectStandardError = true, RedirectStandardOutput = true }; if (this.site.TryGetStartupFileAndDirectory(out var _, out var directory)) { psi.WorkingDirectory = directory; psi.EnvironmentVariables["NODE_PATH"] = directory; } var process = new Process(); process.StartInfo = psi; try { process.Start(); } catch (Exception e) { this.CurrentWindow.WriteError(string.Format(CultureInfo.CurrentCulture, Resources.InteractiveWindowFailedToStartProcessErrorMessage, Environment.NewLine, e.ToString(), Environment.NewLine)); return; } this.listener = new ListenerThread(this, process, socket); }
private void startListener() { // Declare a new listener with local 127.0.0.1 and port 54389 listener = new TcpListener(port); listener.Start(); // Create a new ListenerThread. ListenerThread lt = new ListenerThread(); Thread listenThread = new Thread(new ThreadStart(lt.addPlayers)); listenThread.Start(); // Console.WriteLine("TCP Listener is running"); }
private void ToggleListeningButton_Click(object sender, RoutedEventArgs e) { if (!this.model.IsListening) { this.listener = ListenerThread.Listen(this.model); this.model.IsListening = true; } else { if (this.listener != null) { this.listener.StopListening(); this.model.IsListening = false; } } }
private void SafeExit() { if (PulseThread != null) { if (PulseThread.IsAlive) { PulseThread.Abort(); } } if (ListenerThread != null) { if (ListenerThread.IsAlive) { ListenerThread.Abort(); } } Process.GetCurrentProcess().Kill(); Application.Exit(); }
/// <summary> /// Stop the listener thread /// </summary> public void Stop() { // Request the listener thread to stop StopRequested = true; // A copy of the list of connections to avoid locking IList <T> unlockedConnections = new List <T>(); // Synchronize access to connections collection lock (Connections) { // Iterate over all connections and copy into the local list foreach (T connection in Connections) { unlockedConnections.Add(connection); } } // Iterate over all connections and request each one to stop foreach (T connection in unlockedConnections) { // Request to stop connection.Stop(); } // If server failed to start there is no thread to join if (ListenerThread != null) { // Wait for termination ListenerThread.Join(); } // If server failed to start there is no listener associated with it if (ListenerSocket != null) { // Stop the server ListenerSocket.Stop(); ListenerSocket = null; } }
public override void OnEnable() { main = this; Message.load("the dataNetwork is starting"); Message.load("请确保您的java服务器的指定端口是开启的,使得java服务器可以连接"); //jsmod2的端口 int jsmod2_port; //本代理端口 int this_int_port; //指定的ip String getIp; //读取配置文件 Properties.readInfo(Server, out jsmod2_port, out this_int_port, out getIp); //获取jsmod2的ip对象 ip = new IPEndPoint(IPAddress.Parse(getIp), jsmod2_port);//connect the java smod2 Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); IPEndPoint this_ip = new IPEndPoint(IPAddress.Parse(getIp), this_int_port); server.Bind(this_ip);//绑定本机端口 socket = server; ServerPacket packet = new ServerPacket(); packet.server = Server; sendPacket(packet);//初始化服务器 //把server对象发包 Console.WriteLine("In Main: Listener Thread is starting"); //接收包的线程,监听线程 ListenerThread thread = new ListenerThread(); Thread listenerThread = new Thread(thread.listenerThread); listenerThread.Start();//listener thread }
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(); } }
private void Connect() { if (_listener != null) { _listener.Disconnect(); _listener.Dispose(); _listener = null; } string nodeExePath = GetNodeExePath(); if (String.IsNullOrWhiteSpace(nodeExePath)) { _window.WriteError(SR.GetString(SR.NodejsNotInstalled)); _window.WriteError(Environment.NewLine); return; } else if (!File.Exists(nodeExePath)) { _window.WriteError(SR.GetString(SR.NodeExeDoesntExist, nodeExePath)); _window.WriteError(Environment.NewLine); return; } Socket socket; int port; CreateConnection(out socket, out port); var scriptPath = "\"" + Path.Combine( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "visualstudio_nodejs_repl.js" ) + "\""; var psi = new ProcessStartInfo(nodeExePath, scriptPath + " " + port); psi.CreateNoWindow = true; psi.UseShellExecute = false; psi.RedirectStandardError = true; psi.RedirectStandardOutput = true; string fileName, directory = null; if (_site.TryGetStartupFileAndDirectory(out fileName, out directory)) { psi.WorkingDirectory = directory; psi.EnvironmentVariables["NODE_PATH"] = directory; } var process = new Process(); process.StartInfo = psi; try { process.Start(); } catch (Exception e) { _window.WriteError(String.Format("Failed to start interactive process: {0}{1}{2}", Environment.NewLine, e.ToString(), Environment.NewLine)); return; } _listener = new ListenerThread(this, process, socket); }
private void JoinListener() { ListenerThread.Join(); }
private void ServerStart_Click(object sender, EventArgs e) { ListenerThread.RunWorkerAsync(); }
public SocketLock(ListenerThread evaluator) { Monitor.Enter(evaluator._socketLock); #if DEBUG Debug.Assert(evaluator._socketLockedThread == null); evaluator._socketLockedThread = Thread.CurrentThread; #endif _evaluator = evaluator; }
private void Connect() { if (_listener != null) { _listener.Disconnect(); _listener.Dispose(); _listener = null; } string nodeExePath = GetNodeExePath(); if (String.IsNullOrWhiteSpace(nodeExePath)) { _window.WriteError(Resources.NodejsNotInstalled); _window.WriteError(Environment.NewLine); return; } else if (!File.Exists(nodeExePath)) { _window.WriteError(string.Format(CultureInfo.CurrentCulture, Resources.NodeExeDoesntExist, nodeExePath)); _window.WriteError(Environment.NewLine); return; } Socket socket; int port; CreateConnection(out socket, out port); var scriptPath = "\"" + Path.Combine( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "visualstudio_nodejs_repl.js" ) + "\""; var psi = new ProcessStartInfo(nodeExePath, scriptPath + " " + port); psi.CreateNoWindow = true; psi.UseShellExecute = false; psi.RedirectStandardError = true; psi.RedirectStandardOutput = true; string fileName, directory = null; if (_site.TryGetStartupFileAndDirectory(out fileName, out directory)) { psi.WorkingDirectory = directory; psi.EnvironmentVariables["NODE_PATH"] = directory; } var process = new Process(); process.StartInfo = psi; try { process.Start(); } catch (Exception e) { _window.WriteError(string.Format(CultureInfo.CurrentCulture, Resources.InteractiveWindowFailedToStartProcessErrorMessage, Environment.NewLine, e.ToString(), Environment.NewLine)); return; } _listener = new ListenerThread(this, process, socket); }