Example usage for java.net InetSocketAddress InetSocketAddress

List of usage examples for java.net InetSocketAddress InetSocketAddress

Introduction

In this page you can find the example usage for java.net InetSocketAddress InetSocketAddress.

Prototype

public InetSocketAddress(int port) 

Source Link

Document

Creates a socket address where the IP address is the wildcard address and the port number a specified value.

Usage

From source file:fi.vrk.xroad.catalog.collector.mock.MockHttpServer.java

/**
 * Start http server that offers the given file through http
 * @param fileName file that can be found in classpath
 *///from  www  .  j  av  a 2  s .co m
default void startServer(String fileName) {
    try {
        setServer(HttpServer.create(new InetSocketAddress(PORT), 0));

        getServer().createContext(getContext(fileName), getHandler(fileName));
        getServer().setExecutor(null); // creates a default executor
        log.info("Starting local http server {} in port {}", getServer(), PORT);
        getServer().start();
        // TODO: what about removing this delay?
        TimeUnit.SECONDS.sleep(1);
    } catch (Exception e) {
        throw new CatalogCollectorRuntimeException("Cannot start httpserver", e);
    }
}

From source file:com.linkedin.bowser.tool.REPLServer.java

public REPLServer(Config cfg) {
    _verbose = cfg.getVerbose();//from w ww  .j av a 2  s . c om
    _parallelism = cfg.getParallelism();
    _symbols = cfg.getSymbols();
    _socketAddress = new InetSocketAddress(cfg.getPort());

    _acceptor = new SocketAcceptor();
    _acceptor.getFilterChain().addLast("logger", new LoggingFilter());
    _acceptor.getFilterChain().addLast("codec",
            new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
}

From source file:fm.last.moji.tracker.pool.MultiHostTrackerPoolTest.java

@Before
public void setup() {
    address1 = new InetSocketAddress(10001);
    address2 = new InetSocketAddress(10002);

    when(mockManagedHost1.getAddress()).thenReturn(address1);
    when(mockManagedHost2.getAddress()).thenReturn(address2);
    managedHosts = Arrays.asList(mockManagedHost1, mockManagedHost2);

    when(mockBorrowedTracker1.getHost()).thenReturn(mockManagedHost1);
    when(mockBorrowedTracker2.getHost()).thenReturn(mockManagedHost2);
    trackerPool = new MultiHostTrackerPool(managedHosts, mockNetConfig, mockPool);
}

From source file:inet.encode.SecureMonitor.java

private static void createHttpServer() {
    try {//from w w w  . j  a  v a 2 s.  co m
        server1 = HttpServer.create(new InetSocketAddress(MONITOR_SERVER_PORT), 0);
        //server.setExecutor(null);
        server1.setExecutor(java.util.concurrent.Executors.newCachedThreadPool());
        server1.start();
    } catch (IOException ex) {
        Logger.log(ex);
    }
}

From source file:com.interacciones.mxcashmarketdata.driver.server.DriverServer.java

/**
 * Cierra el socket actual y crea uno nuevo con en mismo handler
 * @throws IOException//ww w .j a  v a2 s  . co m
 */
public static void ResetConnection() throws IOException {
    IoAcceptor newAcceptor = new NioSocketAcceptor();

    newAcceptor.getFilterChain().addLast("logger", new LoggingFilter());
    newAcceptor.setHandler(_acceptor.getHandler());
    _acceptor.dispose();
    newAcceptor.getSessionConfig().setReadBufferSize(65536);
    newAcceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
    newAcceptor.bind(new InetSocketAddress(PORT));
    LOGGER.info("Mina Server Socket ReInitiated");
}

From source file:com.stratio.explorer.socket.ExplorerWebSocketServer.java

public ExplorerWebSocketServer(int port) {
    super(new InetSocketAddress(port));
    creatingwebSocketServerLog(port);
}

From source file:org.sonews.daemon.async.AsynchronousNNTPDaemon.java

@Override
public void run() {
    try {/* ww  w  .j  a va2s .co m*/
        final int workerThreads = Math.max(4, 2 * Runtime.getRuntime().availableProcessors());
        channelGroup = AsynchronousChannelGroup.withFixedThreadPool(workerThreads,
                Executors.defaultThreadFactory());

        serverSocketChannel = AsynchronousServerSocketChannel.open(channelGroup);
        serverSocketChannel.bind(new InetSocketAddress(port));

        serverSocketChannel.accept(null, new AcceptCompletionHandler(serverSocketChannel));

        channelGroup.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
    } catch (IOException | InterruptedException ex) {
        Log.get().log(Level.SEVERE, ex.getLocalizedMessage(), ex);
    }
}

From source file:fi.vrk.xroad.catalog.collector.mock.WsdlMockRestTemplate.java

public void startServer() throws Exception {
    setServer(HttpServer.create(new InetSocketAddress(PORT), 0));
    getServer().createContext("/", new DynamicHttpHandler());
    getServer().setExecutor(null); // creates a default executor
    log.info("Starting local http server {} in port {}", getServer(), PORT);
    getServer().start();/*from  www.j  a  va 2s.  c  o  m*/
}

From source file:com.smith.http.webservice.WebSocketServer.java

public void run() {
    // Configure the server.
    ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
            Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));

    // Set up the event pipeline factory.
    bootstrap.setPipelineFactory(new WebSocketServerPipelineFactory());

    // Bind and start to accept incoming connections.
    bootstrap.bind(new InetSocketAddress(port));

    System.out.println("Web socket server started at port " + port + '.');
    System.out.println("Open your browser and navigate to http://localhost:" + port + '/');
}

From source file:com.zimbra.cs.imap.ImapProxyTest.java

@Test(timeout = 30000)
public void bye() throws Exception {
    server = MockTcpServer.scenario().sendLine("* OK server ready").recvLine() // CAPABILITY
            .sendLine("* CAPABILITY IMAP4rev1 AUTH=X-ZIMBRA")
            .reply(Pattern.compile("(.*) CAPABILITY"), "{0} OK CAPABILITY\r\n").recvLine() // ID
            .sendLine("* ID (\"NAME\" \"Zimbra\")").reply(Pattern.compile("(.*) ID"), "{0} OK ID completed\r\n")
            .recvLine() // AUTHENTICATE
            .sendLine("+ ready for literal")
            .reply(Pattern.compile("(.*) AUTHENTICATE"), "{0} OK AUTHENTICATE\r\n").recvLine() // credential
            .recvLine() // NOOP
            .reply(Pattern.compile("(.*) NOOP"), "{0} OK NOOP\r\n").sendLine("* BYE server closing connection")
            .build().start(PORT);/*  w  w w. j  a v  a2s.co  m*/

    MockImapHandler handler = new MockImapHandler();
    ImapProxy proxy = new ImapProxy(new InetSocketAddress(PORT), "test@zimbra.com", "secret", handler);
    proxy.proxy("001", "NOOP");
    try {
        proxy.proxy("002", "NOOP");
        Assert.fail();
    } catch (ImapProxyException expected) {
    }

    // verify BYE was not proxied
    Assert.assertEquals("001 OK NOOP\r\n", handler.output.toString());

    server.shutdown(3000);
    Assert.assertEquals("C01 CAPABILITY\r\n", server.replay());
    String id = server.replay();
    Assert.assertTrue(id,
            id.matches("C02 ID \\(\"name\" \"ZCS\" \"version\" \".*\" \"X-VIA\" \"127\\.0\\.0\\.1\"\\)\r\n"));
    Assert.assertEquals("C03 AUTHENTICATE X-ZIMBRA\r\n", server.replay());
    server.replay(); // auth token
    Assert.assertEquals("001 NOOP\r\n", server.replay());
    Assert.assertEquals(null, server.replay());
}