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:net.jadler.stubbing.server.jdk.JdkStubHttpServer.java

public JdkStubHttpServer(final int port) {
    isTrue(port >= 0, "port cannot be a negative number");

    try {//from   w  ww .  java2  s .  c o m
        server = HttpServer.create(new InetSocketAddress(port), 0);
    } catch (final IOException e) {
        throw new JadlerException("Cannot create JDK server", e);
    }
}

From source file:com.sittinglittleduck.DirBuster.EasySSLProtocolSocketFactoryUnitTest.java

@BeforeClass
public static void startEmbeddedHttpServers() throws Exception {
    hostConnection = new SocketConnection(new ContainerServer(null));
    hostConnection.connect(new InetSocketAddress(18080));
}

From source file:com.sharneng.net.NetUtils.java

/**
 * Parse an {@link InetSocketAddress} object the given string. The <code>endPoint</code> is in format of
 * <code>[hostname:]port</code>. It can be either a port number, or a hostname and port number separated by the
 * character ':'./*from   w  w  w .j  a va  2  s.c o m*/
 * <p>
 * 
 * For example, '<code>www.company.com:80</code>', '<code>1234</code>' and ' <code>localhost:3344</code>' are all
 * valid end points.
 * 
 * @param endPoint
 *            the string to parse.
 * @return the {@linkplain InetSocketAddress} parsed from string.
 * @exception NumberFormatException
 *                if the port number is not a integer.
 */
public static InetSocketAddress parseInetSocketAddress(String endPoint) {
    String hostname = null;
    String portString;
    int port;

    int index = endPoint.indexOf(":");
    if (index >= 0) {
        hostname = endPoint.substring(0, index);
        portString = endPoint.substring(index + 1);
    } else {
        portString = endPoint;
    }
    port = Integer.parseInt(portString);
    return hostname == null ? new InetSocketAddress(port) : new InetSocketAddress(hostname, port);
}

From source file:com.hellblazer.utils.deserializers.TestInetSocketAddressDeserializer.java

@Test
public void testDeserialization() throws Exception {
    InetSocketAddressDeserializer test = new InetSocketAddressDeserializer();
    InetSocketAddress address = test._deserialize(":0", null);
    assertEquals(new InetSocketAddress(0), address);
    address = test._deserialize("hellblazer.com:666", null);
    assertEquals(new InetSocketAddress("hellblazer.com", 666), address);

    // failure case
    try {/*from  w  w w  .  j a v  a 2s .com*/
        address = test._deserialize("hellblazer.com666", null);
        fail("Should have failed with a bad format exception");
    } catch (InvalidFormatException e) {
        // expected
    }
}

From source file:com.mac.holdempoker.socket.HoldemEndpoint.java

public HoldemEndpoint() {
    super(new InetSocketAddress(PORT));
    this.logger = LoggerFactory.getLogger(this.getClass().getName());
    simpleGame = new SimpleGame();
    simpleGame.start();/*from w w w  .j av  a  2 s  .com*/
    handler = new MessageHandler(simpleGame);
}

From source file:jenkins.plugins.elanceodesk.workplace.notifier.HttpWorkerTest.java

@BeforeClass
public static void setup() throws IOException {
    Container container = new MyHandler();
    Server server = new ContainerServer(container);
    connection = new SocketConnection(server);
    SocketAddress address = new InetSocketAddress(8000);
    connection.connect(address);/*ww w . j  a  v a2s  .c  om*/
}

From source file:jssows.JsonStandardJavaWebSocketServerServices.java

public JsonStandardJavaWebSocketServerServices(int port) throws UnknownHostException {
    super(new InetSocketAddress(port));
    delegator = new JsonStandardWebSocketServerServicesDelegator<>(new JavaWebSocketServerAdapter(this));
}

From source file:kindleclippings.quizlet.GetAccessToken.java

static JSONObject oauthDance() throws IOException, URISyntaxException, InterruptedException, JSONException {

    // start HTTP server, so when can get the authorization code
    InetSocketAddress addr = new InetSocketAddress(7777);
    HttpServer server = HttpServer.create(addr, 0);
    AuthCodeHandler handler = new AuthCodeHandler();
    server.createContext("/", handler);
    ExecutorService ex = Executors.newCachedThreadPool();
    server.setExecutor(ex);/*from  www.  jav  a  2s.c  o m*/
    server.start();
    String authCode;
    try {
        Desktop.getDesktop()
                .browse(new URI(new StringBuilder("https://quizlet.com/authorize/")
                        .append("?scope=read%20write_set").append("&client_id=" + clientId)
                        .append("&response_type=code").append("&state=" + handler.state).toString()));

        authCode = handler.result.take();
    } finally {
        server.stop(0);
        ex.shutdownNow();
    }

    if (authCode == null || authCode.length() == 0)
        return null;

    HttpPost post = new HttpPost("https://api.quizlet.com/oauth/token");
    post.setHeader("Authorization", authHeader);

    post.setEntity(
            new UrlEncodedFormEntity(Arrays.asList(new BasicNameValuePair("grant_type", "authorization_code"),
                    new BasicNameValuePair("code", authCode))));
    HttpResponse response = new DefaultHttpClient().execute(post);

    ByteArrayOutputStream buffer = new ByteArrayOutputStream(1000);
    response.getEntity().writeTo(buffer);
    return new JSONObject(new String(buffer.toByteArray(), "UTF-8"));
}

From source file:com.smartitengineering.cms.binder.guice.InjectionTest.java

@BeforeClass
public static void setUpTests() throws Exception {
    Initializer.init();//from w w w.j a  va  2s .  c o m
    try {
        File snapDir = new File("./target/zk/");
        snapDir.mkdirs();
        ZooKeeperServer server = new ZooKeeperServer(snapDir, snapDir, 2000);
        standaloneServerFactory = new NIOServerCnxn.Factory(new InetSocketAddress(CLIENT_PORT));
        standaloneServerFactory.startup(server);
        if (!AppTest.waitForServerUp(CLIENT_PORT, CONNECTION_TIMEOUT)) {
            throw new IOException("Waiting for startup of standalone server");
        }
    } catch (Exception ex) {
        throw new IllegalStateException(ex);
    }
}

From source file:ab.server.Proxy.java

public Proxy(int port) throws UnknownHostException {
    super(new InetSocketAddress(port));
}