public void Start() { //lock (syncRoot) { if (PublicIp == null) { throw new Exception("Invalid Public IP"); } allocations = new AllocationsPool(); allocations.Removed += Allocation_Removed; ServerAsyncEventArgs.DefaultOffsetOffset = TcpFramingHeader.TcpFramingHeaderLength; turnServer = new ServersManager <TurnConnection>(new ServersManagerConfig()); turnServer.Bind(new ProtocolPort() { Protocol = ServerProtocol.Udp, Port = TurnUdpPort, }); turnServer.Bind(new ProtocolPort() { Protocol = ServerProtocol.Tcp, Port = TurnTcpPort, }); turnServer.Bind(new ProtocolPort() { Protocol = ServerProtocol.Tcp, Port = TurnPseudoTlsPort, }); turnServer.NewConnection += TurnServer_NewConnection; turnServer.Received += TurnServer_Received; turnServer.ServerAdded += TurnServer_ServerAdded; turnServer.ServerRemoved += TurnServer_ServerRemoved; turnServer.Start(true); peerServer = new ServersManager <PeerConnection>( new ServersManagerConfig() { MinPort = MinPort, MaxPort = MaxPort, }); peerServer.AddressPredicate = (i, ip, ai) => { return(ai.Address.Equals(RealIp)); }; peerServer.Received += PeerServer_Received; peerServer.Start(true); peerServer.ServerAdded += PeerServer_ServerAdded; peerServer.ServerRemoved += PeerServer_ServerRemoved; } }
public void Stop() { //lock (syncRoot) { if (allocations != null) { allocations.Clear(); allocations.Removed -= Allocation_Removed; allocations = null; } if (turnServer != null) { turnServer.Dispose(); turnServer = null; } Authentificater = null; } }
public void Start() { //lock (syncRoot) { if (PublicIp == null) throw new Exception("Invalid Public IP"); allocations = new AllocationsPool(); allocations.Removed += Allocation_Removed; ServerAsyncEventArgs.DefaultOffsetOffset = TcpFramingHeader.TcpFramingHeaderLength; turnServer = new ServersManager<TurnConnection>(new ServersManagerConfig()); turnServer.Bind(new ProtocolPort() { Protocol = ServerProtocol.Udp, Port = TurnUdpPort, }); turnServer.Bind(new ProtocolPort() { Protocol = ServerProtocol.Tcp, Port = TurnTcpPort, }); turnServer.Bind(new ProtocolPort() { Protocol = ServerProtocol.Tcp, Port = TurnPseudoTlsPort, }); turnServer.NewConnection += TurnServer_NewConnection; turnServer.Received += TurnServer_Received; turnServer.ServerAdded += TurnServer_ServerAdded; turnServer.ServerRemoved += TurnServer_ServerRemoved; turnServer.Start(true); peerServer = new ServersManager<PeerConnection>( new ServersManagerConfig() { MinPort = MinPort, MaxPort = MaxPort, }); peerServer.AddressPredicate = (i, ip, ai) => { return ai.Address.Equals(RealIp); }; peerServer.Received += PeerServer_Received; peerServer.Start(true); peerServer.ServerAdded += PeerServer_ServerAdded; peerServer.ServerRemoved += PeerServer_ServerRemoved; } }
private void Allocation_Removed(Allocation allocation, AllocationsPool.RemoveReason reason) { logger.WriteInformation(string.Format("Allocation Terminated: {0} <--> {1}, {2}", allocation.Alocated.ToString(), allocation.Reflexive.ToString(), reason.ToString())); peerServer.Unbind(allocation.Alocated.ProtocolPort); }