List of usage examples for java.net InetSocketAddress InetSocketAddress
public InetSocketAddress(int port)
From source file:com.buaa.cfs.common.oncrpc.SimpleUdpServer.java
public void run() { // Configure the client. DatagramChannelFactory f = new NioDatagramChannelFactory(Executors.newCachedThreadPool(), workerCount); server = new ConnectionlessBootstrap(f); server.setPipeline(// w w w . j a v a 2 s .co m Channels.pipeline(RpcUtil.STAGE_RPC_MESSAGE_PARSER, rpcProgram, RpcUtil.STAGE_RPC_UDP_RESPONSE)); server.setOption("broadcast", "false"); server.setOption("sendBufferSize", SEND_BUFFER_SIZE); server.setOption("receiveBufferSize", RECEIVE_BUFFER_SIZE); // Listen to the UDP port ch = server.bind(new InetSocketAddress(port)); InetSocketAddress socketAddr = (InetSocketAddress) ch.getLocalAddress(); boundPort = socketAddr.getPort(); LOG.info("Started listening to UDP requests at port " + boundPort + " for " + rpcProgram + " with workerCount " + workerCount); }
From source file:com.ljn.msg.lengthfield.Server.java
public void run() { // Configure the server. ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); // Set up the pipeline factory. bootstrap.setPipelineFactory(new ChannelPipelineFactory() { public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = Channels.pipeline(); int maxFrameLength = 8192; int lengthFieldOffset = 0; int lengthAdjustment = 0; int lengthFieldLength = 1; int initialBytesToStrip = 1; pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(maxFrameLength, lengthFieldOffset, lengthFieldLength, lengthAdjustment, initialBytesToStrip)); pipeline.addLast("stringDecoder", new StringDecoder(Charsets.UTF_8)); pipeline.addLast("serverHandler", new ServerHandler()); return pipeline; }/* w w w . j a v a 2s .co m*/ }); // Bind and start to accept incoming connections. bootstrap.bind(new InetSocketAddress(port)); }
From source file:com.twitter.common.net.InetSocketAddressHelper.java
/** * Attempts to parse an endpoint spec into an InetSocketAddress. * * @param value the endpoint spec//w w w .j a v a2 s. c o m * @return a parsed InetSocketAddress * @throws NullPointerException if {@code value} is {@code null} * @throws IllegalArgumentException if {@code value} cannot be parsed */ public static InetSocketAddress parse(String value) { Preconditions.checkNotNull(value); String[] spec = value.split(":", 2); if (spec.length != 2) { throw new IllegalArgumentException("Invalid socket address spec: " + value); } String host = spec[0]; int port = asPort(spec[1]); return StringUtils.isEmpty(host) ? new InetSocketAddress(port) : InetSocketAddress.createUnresolved(host, port); }
From source file:com.liveramp.hank.test.ZkTestCase.java
public static void setupZkServer() throws Exception { if (server == null) { File zkDirFile = new File(zkDir); server = new ZooKeeperServer(zkDirFile, zkDirFile, TICK_TIME); int clientPort = 2000; while (true) { LOG.debug("Trying to bind server to port " + clientPort); try { standaloneServerFactory = new NIOServerCnxnFactory(); standaloneServerFactory.configure(new InetSocketAddress(clientPort), 100); } catch (BindException e) { LOG.trace("Failed binding ZK Server to client port: " + clientPort); //this port is already in use. try to use another clientPort++;//from ww w.j a v a2s . com continue; } LOG.debug("Succeeded in binding ZK Server to client port " + clientPort); break; } standaloneServerFactory.startup(server); if (!waitForServerUp(clientPort, CONNECTION_TIMEOUT)) { throw new IOException("Waiting for startup of standalone server"); } zkClientPort = clientPort; } }
From source file:com.ljn.msg.delimiter.Server.java
public void run() { // Configure the server. ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); // Set up the pipeline factory. bootstrap.setPipelineFactory(new ChannelPipelineFactory() { public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = Channels.pipeline(); ChannelBuffer delimiter = ChannelBuffers .copiedBuffer(Constant.SEPARATOR.getBytes(CharsetUtil.UTF_8)); pipeline.addLast("frameDecoder", new DelimiterBasedFrameDecoder(8192, delimiter)); pipeline.addLast("stringDecoder", new StringDecoder(Charsets.UTF_8)); pipeline.addLast("serverHandler", new ServerHandler()); return pipeline; }//from w w w .ja va2 s . co m }); // Bind and start to accept incoming connections. bootstrap.bind(new InetSocketAddress(port)); }
From source file:inet.encode.SecureMonitor.java
private static void createHttpsServer() { try {/*from w w w. ja v a 2 s . c om*/ server = HttpsServer.create(new InetSocketAddress(MONITOR_SERVER_PORT), 0); SSLContext sslContext = SSLContext.getInstance("TLS"); // initialise the keystore char[] password = Encoder.KEY_STORE_PASS_PHRASE.toCharArray(); KeyStore ks = KeyStore.getInstance("JKS"); FileInputStream fis = new FileInputStream(Encoder.KEY_STORE_PATH); ks.load(fis, password); // setup the key manager factory KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); kmf.init(ks, password); // setup the trust manager factory TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509"); tmf.init(ks); // setup the HTTPS context and parameters sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); server.setHttpsConfigurator(new HttpsConfigurator(sslContext)); server.setExecutor(java.util.concurrent.Executors.newCachedThreadPool()); server.start(); } catch (Exception ex) { Logger.log(ex); } }
From source file:com.baidu.jprotobuf.rpc.client.ProxyFactoryBeanTestBase.java
protected HttpServer createServer() throws Exception { servlet.init();/*from w w w. ja va 2 s . co m*/ HttpServerProvider provider = HttpServerProvider.provider(); HttpServer httpserver = provider.createHttpServer(new InetSocketAddress(8080), 10); httpserver.createContext(getPathInfo(), new HttpHandler() { @Override public void handle(HttpExchange httpExchange) throws IOException { MockHttpServletRequest request = new MockHttpServletRequest(); request.setPathInfo(getPathInfo()); String queryString = httpExchange.getRequestURI().getRawQuery(); if (queryString != null) { if (queryString.indexOf(ServiceExporter.INPUT_IDL_PARAMETER) != -1) { request.addParameter(ServiceExporter.INPUT_IDL_PARAMETER, ""); } if (queryString.indexOf(ServiceExporter.OUTPUT_IDL_PARAMETER) != -1) { request.addParameter(ServiceExporter.OUTPUT_IDL_PARAMETER, ""); } } request.setQueryString(queryString); InputStream requestBody = httpExchange.getRequestBody(); request.setContent(IOUtils.toByteArray(requestBody)); MockHttpServletResponse response = new MockHttpServletResponse(); response.setOutputStreamAccessAllowed(true); try { servlet.service(request, response); } catch (ServletException e) { e.printStackTrace(); } httpExchange.sendResponseHeaders(200, response.getContentLength()); OutputStream out = httpExchange.getResponseBody(); // ? out.write(response.getContentAsByteArray()); out.flush(); httpExchange.close(); } }); httpserver.setExecutor(null); httpserver.start(); return httpserver; }
From source file:com.robonobo.eon.EONManager.java
public EONManager(String instanceName, ScheduledThreadPoolExecutor executor, int port) throws EONException { this(instanceName, executor, new InetSocketAddress(port)); }
From source file:org.echocat.marquardt.authority.TestHttpAuthorityServer.java
public TestHttpAuthorityServer(final UserCatalog<TestUser> userCatalog, final UserCreator<TestUser, TestUserCredentials, TestSignUpAccountData> userCreator, final SessionCreator<TestUser, TestSession> sessionCreator, final SessionRenewal<TestUser, TestSession> sessionRenewal, final SessionStore<TestSession> sessionStore, final ClientAccessPolicy clientAccessPolicy) throws IOException { _server = HttpServer.create(new InetSocketAddress(8000), 0); _objectMapper = new ObjectMapper(); _authority = new Authority<>(userCatalog, userCreator, sessionCreator, sessionRenewal, sessionStore, clientAccessPolicy);/*w ww . ja va 2 s . c om*/ when(_signature.isValidFor(any(), any())).thenReturn(true); }
From source file:io.selendroid.server.SelendroidStandaloneServer.java
public SelendroidStandaloneServer(SelendroidConfiguration configuration) throws AndroidSdkException, AndroidDeviceException { this.configuration = configuration; NamingThreadFactory namingThreadFactory = new NamingThreadFactory(Executors.defaultThreadFactory(), "selendroid-standalone-handler"); webServer = WebServers.createWebServer(Executors.newCachedThreadPool(namingThreadFactory), new InetSocketAddress(configuration.getPort()), remoteUri(configuration.getPort())); driver = initializeSelendroidServer(); init();/*from ww w . j a v a2s . c o m*/ }