private static void Listening(object state) { UDPDuplexListener listener = (UDPDuplexListener)state; UDPListener udpListener = new UDPListener(new IPEndPoint(IPAddress.Loopback, 13001), 2); try { udpListener.Start(); if (listener.started != null) { listener.started(); } Console.WriteLine("Servidor de áudio iniciado na porta " + udpListener.LocalIPEndPoint.Port.ToString()); while (true) { UDPClient client = udpListener.AcceptClient(); listener.clientAccepted(new UDPDuplexCommunication(client)); } } catch (SocketException e) { Console.WriteLine("SocketException: {0}", e); } finally { // Stop listening for new clients. udpListener.Stop(); } }
public void Stop() { if (stopped) { return; } stopped = true; _tcpListener?.Stop(); _udpListener?.Stop(); StopPlugins(); if (privoxyRunner != null) { privoxyRunner.Stop(); } if (_config.enabled) { SystemProxy.Update(_config, true, null); } }
/// <summary> /// /// </summary> void StartListening() { UDPListener listener = new UDPListener(this); listener.Start(); Console.ReadKey(); listener.Stop(); }
public void StopServer() { if (server != null) { ConnectionPacket cP = new ConnectionPacket(true, "Server Closed."); Packet p = new Packet(Packet.pType.connectionPacket, Packet.sendType.nonbuffered, ENSSerialization.SerializeConnectionPacket(cP)); foreach (NetworkPlayer client in connections) { SendPacket(client, p); //Server Closed Packet. client.tcpClient.Close(); client.tcpClient.Dispose(); } server.Stop(); server = null; if (useSteamworks && !NetTools.isSingleplayer) { SteamInteraction.instance.ShutdownServer(); } UPnP.Shutdown(); } if (udpListener != null) { udpListener.Stop(); udpListener = null; } if (connectionHandler != null) { connectionHandler.Abort(); connectionHandler = null; } if (udpHandler != null) { udpHandler.Abort(); udpHandler = null; } if (GameObject.FindObjectOfType <UnityPacketHandler>() != null) { GameObject.Destroy(GameObject.FindObjectOfType <UnityPacketHandler>().gameObject); } //NetServer.serverInstance = null; connections = new List <NetworkPlayer>(); connectionsByID = new Dictionary <int, NetworkPlayer>(); bufferedPackets = new Dictionary <string, List <Packet> >(); if (NetServer.serverInstance != null && NetServer.serverInstance.myConnection != null) { NetServer.serverInstance.myConnection = null; } NetTools.isServer = false; NetTools.isSingleplayer = false; }
private void ClosedSend() { try { //用UDP协议发送广播 Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); try { for (int i = 2; i < 256; i++) { if (this.locIPLast != i) { string ip = this.locIPHead + i.ToString(); //设置端口号为9124 IPEndPoint iep = new IPEndPoint(IPAddress.Parse(ip), 9124); //设置broadcast值为1,允许套接字发送广播信息 socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1); //将发送内容转换为字节数组 byte[] bytes = System.Text.Encoding.Unicode.GetBytes("AK" + locIPHead + locIPLast.ToString()); //向子网发送信息 socket.SendTo(bytes, iep); } } } catch (Exception ex) { Console.WriteLine(ex); } finally { socket.Close(); } if (udpListener != null) { udpListener.Stop(); } if (thread != null) { try { thread.Abort(); } catch (Exception) { } } } catch (Exception ex) { Console.WriteLine(ex); } }
void RunUDPServer() { UDPListener listener = new UDPListener(NetworkingLibaryStandard.NetworkingLibaryStandard.DefaultPortNumber, this); listener.Start(); Console.WriteLine("Press any Key to stop"); Console.ReadKey(); listener.Stop(); Console.WriteLine("They System Has stoped"); }
private void StopPolling() { pollOnceToolStripMenuItem.Enabled = true; startPollingToolStripMenuItem.Enabled = true; stopPollingToolStripMenuItem.Enabled = false; timer1.Enabled = false; UDPListener.Stop(); if (typeof(IOutputs).IsAssignableFrom(pokeys.Driver.GetType())) { IOutputs driver = (IOutputs)pokeys.Driver; UDPListener.MessageReceived -= driver.UDPListenerEventHandlerMessageReceived; } pollingStatusLabel.Text = "Polling:OFF"; }
/// <summary> /// /// </summary> void RunUDPDemoToms() { UDPClient client = new UDPClient(this); UDPListener listener = new UDPListener(NetworkingLibaryStandard.NetworkingLibaryStandard.DefaultPortNumber + 1, this); listener.Start(); client.Start(); client.Send("Hello World"); Console.ReadKey(); client.Disconnect(); listener.Stop(); }
private void ClosedSend() { try { SendMess("Error"); if (udpListener != null) { udpListener.Stop(); } if (socket != null) { socket.Close(); } } catch (Exception ex) { Console.WriteLine(ex); } }
public void Stop() { Log.Info(type, "Stopping networking.."); listener.Stop(); }
public void Stop() { _tcpListener?.Stop(); _udpListener?.Stop(); }