@Override public void close() throws IOException { container.onServerStop(); analyzer.stop(); connection.close(); }
@AfterClass public static void stopServer() throws IOException { if (null != socketConnection) { socketConnection.close(); } }
final SimpleTraceAnalyzer analyzer = new SimpleTraceAnalyzer(); final SocketProcessor server = serverProvider.get(); connection = new SocketConnection(server, analyzer); final SocketAddress socketAddr = connection.connect(listen, context); container.onServerStart();
@BeforeClass public static void startServer() throws IOException { socketConnection = new SocketConnection(new Container() { public void handle(Request req, Response resp) { try { SocketAddress address = socketConnection.connect(new InetSocketAddress("localhost", 0));
eg : SocketConnection connection = new SocketConnection(); String token = "message that you want to write on server"; String response = connecation.EstablishConnection(token);
/** * This creates a new background task that will listen to the * specified <code>ServerAddress</code> for incoming TCP connect * requests. When an connection is accepted it is handed to the * internal socket connector. * * @param address this is the address used to accept connections * * @return this returns the actual local address that is used */ public SocketAddress connect(SocketAddress address) throws IOException { if(closed) { throw new ConnectionException("Connection is closed"); } return manager.listen(address); }
/** * This is used to register the socket acceptor to listen for * new connections that are ready to be accepted. Once this is * registered it will remain registered until the interface is * closed, at which point the socket is closed. */ public void process() throws IOException { try { acceptor.bind(); reactor.process(acceptor, OP_ACCEPT); } catch(Exception cause) { throw new ConnectionException("Listen error", cause); } }
/** * This is used to close the connection and the server socket * used to accept connections. This will perform a close of the * connected server socket and the dispatching thread. */ public void close() throws IOException { try { acceptor.close(); reactor.stop(); } catch(Exception cause) { throw new ConnectionException("Close error", cause); } } }
/** * This is used to acquire the local socket address that this is * listening to. This required in case the socket address that * is specified is an emphemeral address, that is an address that * is assigned dynamically when a port of 0 is specified. * * @return this returns the address for the listening address */ public SocketAddress getAddress() { return acceptor.getAddress(); }
/** * This is used to cancel the operation if the reactor decides to * reject it for some reason. Typically this method will never be * invoked as this operation never times out. However, should the * reactor cancel the operation this will close the socket. */ public void cancel() { try { close(); } catch(Throwable e) { return; } }
/** * This creates a new background task that will listen to the * specified <code>ServerAddress</code> for incoming TCP connect * requests. When an connection is accepted it is handed to the * internal socket connector. * * @param address this is the address used to accept connections * * @return this returns the actual local address that is used */ public SocketAddress listen(SocketAddress address) throws IOException { return listen(address, null); }
/** * This method is used to accept an event that occurred on the socket * associated with this trace. Typically the event is a symbolic * description of the event such as an enum or a string. * * @param event this is the event that occurred on the socket */ public void trace(Object event) { trace(event, null); }
/** * Constructor for the <code>SocketListenerManager</code> object. * This is used to create a manager that will enable listeners to * be created to listen to specified sockets for incoming TCP * connections, which will be converted to socket objects. * * @param server this is the server that sockets are handed to * @param agent this is the agent used to trace socket events */ public SocketListenerManager(Server server, Agent agent) { this.agent = new SocketAgent(agent); this.server = server; }
logger.info("Starting BitTorrent tracker on {}...", getAnnounceUrl()); connection = new SocketConnection(new ContainerServer(myTrackerServiceContainer)); for (SocketAddress address : tries) { try { if ((myBoundAddress = connection.connect(address)) != null) { logger.info("Started torrent tracker on {}", address); started = true;
/** * Stop the tracker. * <p> * <p> * This effectively closes the listening HTTP connection to terminate * the service, and interrupts the peer myPeerCollectorThread thread as well. * </p> */ public void stop() { this.stop = true; try { this.connection.close(); logger.info("BitTorrent tracker closed."); } catch (IOException ioe) { logger.error("Could not stop the tracker: {}!", ioe.getMessage()); } if (myPeerCollectorThread != null && myPeerCollectorThread.isAlive()) { myPeerCollectorThread.interrupt(); try { myPeerCollectorThread.join(); } catch (InterruptedException e) { // } logger.info("Peer collection terminated."); } }
/** * This is used to acquire the local socket address that this is * listening to. This required in case the socket address that * is specified is an emphemeral address, that is an address that * is assigned dynamically when a port of 0 is specified. * * @return this returns the address for the listening address */ public SocketAddress getAddress() { return acceptor.getAddress(); }
/** * Closes the server. * * @throws IOException In case closing fails. */ public void stop() throws IOException { connection.close(); }
/** * This is used to acquire the local socket address that this is * listening to. This required in case the socket address that * is specified is an emphemeral address, that is an address that * is assigned dynamically when a port of 0 is specified. * * @return this returns the address for the listening address */ public SocketAddress getAddress() { return acceptor.getAddress(); }
/** * Closes the HTTP server */ public void stop() { if (this.connection != null) { try { this.connection.close(); } catch (IOException e) { } } }
@Override public void stop() throws Exception { connection.close(); }