/** * Creates a new, empty SessionDescription. The session is set as follows: * * <p>v=0 * * <p>o=this.createOrigin ("user", NetworkUtils.getLocalHost().toString()); * * <p>s=- * * <p>t=0 0 * * @throws SdpException SdpException, - if there is a problem constructing the SessionDescription. * @return a new, empty SessionDescription. */ public SessionDescription createSessionDescription() throws SdpException { SessionDescriptionImpl sessionDescriptionImpl = new SessionDescriptionImpl(); ProtoVersionField ProtoVersionField = new ProtoVersionField(); ProtoVersionField.setVersion(0); sessionDescriptionImpl.setVersion(ProtoVersionField); OriginField originImpl = null; try { originImpl = (OriginField) this.createOrigin("user", NetworkUtils.getLocalHost().getHostAddress()); } catch (UnknownHostException e) { e.printStackTrace(); } sessionDescriptionImpl.setOrigin(originImpl); SessionNameField sessionNameImpl = new SessionNameField(); sessionNameImpl.setValue("-"); sessionDescriptionImpl.setSessionName(sessionNameImpl); TimeDescriptionImpl timeDescriptionImpl = new TimeDescriptionImpl(); TimeField timeImpl = new TimeField(); timeImpl.setZero(); timeDescriptionImpl.setTime(timeImpl); Vector times = new Vector(); times.addElement(timeDescriptionImpl); sessionDescriptionImpl.setTimeDescriptions(times); // Dan Muresan: this was a memory leak // sessionDescriptionsList.addElement(sessionDescriptionImpl); return sessionDescriptionImpl; }
@Override public synchronized int addUpnpMapping( final PortMappingProtocol prot, final int localPort, final int externalPortRequested, final PortMapListener portMapListener) { if (NetworkUtils.isPublicAddress()) { // Return value is not used. return 1; } // This call will block unless we thread it here. final Runnable upnpRunner = new Runnable() { @Override public void run() { addMapping(prot, externalPortRequested, localPort, portMapListener); } }; final Thread mapper = new Thread(upnpRunner, "UPnP-Mapping-Thread"); mapper.setDaemon(true); mapper.start(); // Return value is not used. return 1; }
private InetSocketAddress startThreadedServer() throws UnknownHostException { final InetSocketAddress serverAddress = new InetSocketAddress(NetworkUtils.getLocalHost(), 7896); final Runnable runner = new Runnable() { public void run() { try { startServer(serverAddress); } catch (final Throwable t) { fail("Bad, bad server"); } } }; final Thread turnThread = new Thread(runner, "TURN-Test-Data-Server-Thread"); turnThread.setDaemon(true); turnThread.start(); return serverAddress; }
/** * Creates a new mapped server for the answerer. * * @param natPmpService The NAT PMP mapper. * @param upnpService The UPnP mapper. * @param serverAddress The address of the server. * @throws IOException If there's an error starting the server. */ public MappedTcpAnswererServer( final NatPmpService natPmpService, final UpnpService upnpService, final InetSocketAddress serverAddress) throws IOException { if (serverAddress.getPort() == 0) { throw new IllegalArgumentException("Cannot map ephemeral port"); } final int port = serverAddress.getPort(); this.serverAddress = new InetSocketAddress(NetworkUtils.getLocalHost(), port); // We just set the port to the local port for now, as that's the one // we're requesting on the router. If the router does set it to a // different port, we'll get notified and will reset it. this.m_externalPort = port; upnpService.addUpnpMapping(PortMappingProtocol.TCP, port, port, MappedTcpAnswererServer.this); natPmpService.addNatPmpMapping( PortMappingProtocol.TCP, port, port, MappedTcpAnswererServer.this); }