List of usage examples for java.net InetSocketAddress getHostString
public final String getHostString()
From source file:org.apache.hadoop.ipc.RpcSSLEngineAbstr.java
private String getRemoteHost() { try {// w w w .ja v a 2 s. c o m SocketAddress remoteAddress = socketChannel.getRemoteAddress(); if (remoteAddress == null) { return "unknown"; } if (remoteAddress instanceof InetSocketAddress) { InetSocketAddress inetRemoteAddress = (InetSocketAddress) remoteAddress; return inetRemoteAddress.getHostString() + ":" + inetRemoteAddress.getPort(); } return "unknown"; } catch (IOException ex) { return "unknown"; } }
From source file:com.spotify.helios.ZooKeeperClusterTestManager.java
private List<String> endpoints(final Iterable<InetSocketAddress> addresses) { return ImmutableList.copyOf(transform(addresses, new Function<InetSocketAddress, String>() { @Override//www . j a va2s. co m public String apply(final InetSocketAddress addr) { return addr.getHostString() + ":" + addr.getPort(); } })); }
From source file:me.jtalk.socketconnector.SocketResourceAdapter.java
public long listenTCP(long clientId, InetSocketAddress local) throws ResourceException { log.trace("TCP listening requested for client ''{}'', address ''{}:{}''", clientId, local.getHostString(), local.getPort());//w w w . j av a 2 s . co m TCPManager manager = this.getTCPManagerChecked(clientId); return manager.listen(local); }
From source file:me.jtalk.socketconnector.SocketResourceAdapter.java
public long createTCPConnection(long clientId, InetSocketAddress target) throws ResourceException { log.trace("TCP connection creation requested for client ''{}'', address ''{}:{}''", clientId, target.getHostString(), target.getPort()); TCPManager manager = this.getTCPManagerChecked(clientId); return manager.connect(target); }
From source file:org.zxg.network.dhtcrawler.Crawler.java
@Override protected UdpMsg recvUdp() throws IOException { byte[] buffer = new byte[65536]; DatagramPacket datagramPacket = new DatagramPacket(buffer, buffer.length); socket.receive(datagramPacket);//from w ww . j ava 2 s. c o m UdpMsg msg = new UdpMsg(); msg.data = new byte[datagramPacket.getLength()]; System.arraycopy(datagramPacket.getData(), datagramPacket.getOffset(), msg.data, 0, datagramPacket.getLength()); InetSocketAddress socketAddress = (InetSocketAddress) datagramPacket.getSocketAddress(); msg.addr = new Addr(socketAddress.getHostString(), socketAddress.getPort()); return msg; }
From source file:org.elasticsearch.xpack.security.authc.saml.SamlAuthenticationIT.java
private URI getWebServerUri() { final InetSocketAddress address = httpServer.getAddress(); final String host = address.getHostString(); final int port = address.getPort(); try {//from w w w.j a va 2s.c om return new URI("http", null, host, port, "/", null, null); } catch (URISyntaxException e) { throw new ElasticsearchException("Cannot construct URI for httpServer @ {}:{}", e, host, port); } }
From source file:com.raphfrk.craftproxyclient.net.protocol.p17xlogin.P17xLoginProtocol.java
@Override public Protocol handleLogin(Handshake handshake, PacketChannel client, PacketChannel server, InetSocketAddress serverAddr) throws IOException { P17xHandshake h = (P17xHandshake) handshake; if (h.getNextState() != 2) { sendKick("Unknown handshake next state " + h.getNextState(), client); return null; }/* ww w . j av a 2 s . co m*/ h.setServerPort(serverAddr.getPort()); h.setServerhost(serverAddr.getHostString()); server.setRegistry(handshakePacketRegistry); server.writePacket(h); server.setRegistry(getPacketRegistry()); int id = client.getPacketId(); if (this.isKickMessage(id, true)) { client.transferPacket(server); sendKick("Kick message received from client", client); return null; } else if (id != 0) { sendKick("Expected LoginStart message", client); return null; } P17xLoginStart loginStart = new P17xLoginStart(client.getPacket()); if (loginStart.getUsername() == null || !loginStart.getUsername().equals(AuthManager.getUsername())) { sendKick("Login mismatch, proxy logged as " + AuthManager.getUsername() + " client logged in as " + loginStart.getUsername(), client); return null; } server.writePacket(loginStart); id = server.getPacketId(); if (this.isKickMessage(id, false)) { server.transferPacket(client); return null; } else if (id != 0x01 && id != 0x02) { sendKick("Expecting Encrypt Key Request or Login Success packet from server, got " + id, client); return null; } if (id == 0x01) { P17xEncryptionKeyRequest request = new P17xEncryptionKeyRequest(server.getPacket()); byte[] secret = Crypt.getBytes(16); if (!authSession(secret, client, request)) { return null; } if (!sendEncryptionKeyResponse(secret, client, server, request)) { return null; } enableEncryption(server, client, secret); } else { setMultiByteChannels(server, client); } id = server.getPacketId(); if (this.isKickMessage(id, false)) { server.transferPacket(client); return null; } if (id != 0x02) { System.out.println("Id is " + id); sendKick("Expecting Login Success packet, got " + id, client); return null; } P17xLoginSuccess success = new P17xLoginSuccess(server.getPacket()); client.writePacket(success); return p172Protocol; }
From source file:org.echocat.jomon.net.service.UriBasedServicesManager.java
@Nonnull protected URI toUri(@Nonnull URI original, @Nonnull InetSocketAddress address) { final String scheme = original.getScheme(); final int port = address.getPort(); final String userInfo = original.getRawUserInfo(); final String path = original.getRawPath(); final String query = original.getRawQuery(); final String fragment = original.getRawFragment(); final StringBuilder sb = new StringBuilder(); sb.append(scheme).append("://"); if (isNotEmpty(userInfo)) { sb.append(userInfo).append('@'); }//w w w. j av a 2s. co m sb.append(address.getHostString()); if (canAppendPort(scheme, port)) { sb.append(':').append(port); } if (isNotEmpty(path)) { sb.append(path); } if (isNotEmpty(query)) { sb.append('?').append(query); } if (isNotEmpty(fragment)) { sb.append('#').append(fragment); } return URI.create(sb.toString()); }
From source file:com.beyondj.gateway.handlers.detecting.DetectingGateway.java
public void handle(final SocketWrapper socket) { shutdownTacker.retain();/*from w w w .j av a 2 s. co m*/ receivedConnectionAttempts.incrementAndGet(); socketsConnecting.add(socket); if (connectionTimeout > 0) { vertx.setTimer(connectionTimeout, new Handler<Long>() { public void handle(Long timerID) { if (socketsConnecting.contains(socket)) { handleConnectFailure(socket, String .format("Gateway client '%s' protocol detection timeout.", socket.remoteAddress())); } } }); } ReadStream<ReadStream> readStream = socket.readStream(); readStream.exceptionHandler(new Handler<Throwable>() { @Override public void handle(Throwable e) { handleConnectFailure(socket, String.format("Failed to route gateway client '%s' due to: %s", socket.remoteAddress(), e)); } }); readStream.endHandler(new Handler<Void>() { @Override public void handle(Void event) { handleConnectFailure(socket, String.format("Gateway client '%s' closed the connection before it could be routed.", socket.remoteAddress())); } }); readStream.dataHandler(new Handler<Buffer>() { Buffer received = new Buffer(); @Override public void handle(Buffer event) { received.appendBuffer(event); for (final Protocol protocol : protocols) { if (protocol.matches(received)) { if ("ssl".equals(protocol.getProtocolName())) { LOG.info(String.format("SSL Connection from '%s'", socket.remoteAddress())); String disabledCypherSuites = null; String enabledCipherSuites = null; if (sslConfig != null) { disabledCypherSuites = sslConfig.getDisabledCypherSuites(); enabledCipherSuites = sslConfig.getEnabledCipherSuites(); } if (sslContext == null) { try { if (sslConfig != null) { sslContext = SSLContext.getInstance(sslConfig.getProtocol()); sslContext.init(sslConfig.getKeyManagers(), sslConfig.getTrustManagers(), null); } else { sslContext = SSLContext.getDefault(); } } catch (Exception e) { handleConnectFailure(socket, "Could initialize SSL: " + e); return; } } // lets wrap it up in a SslSocketWrapper. SslSocketWrapper sslSocketWrapper = new SslSocketWrapper(socket); sslSocketWrapper.putBackHeader(received); sslSocketWrapper.initServer(sslContext, clientAuth, disabledCypherSuites, enabledCipherSuites); DetectingGateway.this.handle(sslSocketWrapper); return; } else if ("http".equals(protocol.getProtocolName())) { InetSocketAddress target = getHttpGateway(); if (target != null) { try { URI url = new URI("http://" + target.getHostString() + ":" + target.getPort()); LOG.info(String.format("Connecting '%s' to '%s:%d' using the http protocol", socket.remoteAddress(), url.getHost(), url.getPort())); ConnectionParameters params = new ConnectionParameters(); params.protocol = "http"; createClient(params, socket, url, received); return; } catch (URISyntaxException e) { handleConnectFailure(socket, "Could not build valid connect URI: " + e); return; } } else { handleConnectFailure(socket, "No http gateway available for the http protocol"); return; } } else { protocol.snoopConnectionParameters(socket, received, new Handler<ConnectionParameters>() { @Override public void handle(ConnectionParameters connectionParameters) { // this will install a new dataHandler on the socket. if (connectionParameters.protocol == null) connectionParameters.protocol = protocol.getProtocolName(); if (connectionParameters.protocolSchemes == null) connectionParameters.protocolSchemes = protocol .getProtocolSchemes(); route(socket, connectionParameters, received); } }); return; } } } if (received.length() >= maxProtocolIdentificationLength) { handleConnectFailure(socket, "Connection did not use one of the enabled protocols " + getProtocolNames()); } } }); }
From source file:org.apache.pulsar.client.impl.ClientCnx.java
void setTargetBroker(InetSocketAddress targetBrokerAddress) { this.proxyToTargetBrokerAddress = String.format("%s:%d", targetBrokerAddress.getHostString(), targetBrokerAddress.getPort()); }