Java Code Examples for java.net.Socket#getPort()
The following examples show how to use
java.net.Socket#getPort() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: PADListener File: NetworkHostNameResolver.java License: GNU General Public License v2.0 | 6 votes |
private SiteData parseData(Socket socket, int _destPort){ SiteData newSiteData = new SiteData(); String originalDest = getOriginalDest(socket); String[] tokens = originalDest.split(":"); if (tokens.length == 2){ String destIP = tokens[0]; String hostName = DNSProxy.getHostNameFromIp(destIP); int destPort = Integer.parseInt(tokens[1]); if (destPort != _destPort && _destPort > 0){ destPort = _destPort; } newSiteData.destPort = destPort; newSiteData.tcpAddress = destIP; newSiteData.sourcePort = socket.getPort(); newSiteData.hostName = hostName; newSiteData.name = ""; }else{ } return newSiteData; }
Example 2
Source Project: ignite File: IgniteClientRejoinTest.java License: Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected void writeToSocket(Socket sock, TcpDiscoveryAbstractMessage msg, byte[] data, long timeout) throws IOException { if (blockAll || block && sock.getPort() == 47500) throw new SocketException("Test discovery exception"); super.writeToSocket(sock, msg, data, timeout); }
Example 3
Source Project: ignite File: IgniteClientRejoinTest.java License: Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected void writeToSocket(TcpDiscoveryAbstractMessage msg, Socket sock, int res, long timeout) throws IOException { if (blockAll || block && sock.getPort() == 47500) throw new SocketException("Test discovery exception"); super.writeToSocket(msg, sock, res, timeout); }
Example 4
Source Project: ignite File: IgniteClientRejoinTest.java License: Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected Socket openSocket(Socket sock, InetSocketAddress remAddr, IgniteSpiOperationTimeoutHelper timeoutHelper) throws IOException, IgniteSpiOperationTimeoutException { if (blockAll || block && sock.getPort() == 47500) throw new SocketException("Test discovery exception"); return super.openSocket(sock, remAddr, timeoutHelper); }
Example 5
Source Project: NetBare File: TcpProxyServer.java License: MIT License | 5 votes |
private void onAccept() throws IOException { SocketChannel clientChannel = mServerSocketChannel.accept(); Socket clientSocket = clientChannel.socket(); // The client ip is the remote server ip // The client port is the local port(it is the vpn port not the proxy server port) String ip = clientSocket.getInetAddress().getHostAddress(); int port = clientSocket.getPort(); // The session should have be saved before the tcp packets be forwarded to proxy server. So // we can query it by client port. Session session = mSessionProvider.query((short) port); if (session == null) { throw new IOException("No session saved with key: " + port); } int remotePort = NetBareUtils.convertPort(session.remotePort); // Connect remote server and dispatch data. TcpTunnel proxyTunnel = null; TcpTunnel remoteTunnel = null; try { proxyTunnel = new TcpProxyTunnel(clientChannel, mSelector, remotePort); remoteTunnel = new TcpRemoteTunnel(mVpnService, SocketChannel.open(), mSelector, ip, remotePort); TcpVATunnel gatewayTunnel = new TcpVATunnel(session, proxyTunnel, remoteTunnel, mMtu); gatewayTunnel.connect(new InetSocketAddress(ip, remotePort)); } catch (IOException e){ NetBareUtils.closeQuietly(proxyTunnel); NetBareUtils.closeQuietly(remoteTunnel); throw e; } }
Example 6
Source Project: ignite File: IgniteClientRejoinTest.java License: Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected void writeToSocket(Socket sock, TcpDiscoveryAbstractMessage msg, long timeout) throws IOException, IgniteCheckedException { if (blockAll || block && sock.getPort() == 47500) throw new SocketException("Test discovery exception"); super.writeToSocket(sock, msg, timeout); }
Example 7
Source Project: jdk8u_jdk File: TestSocketFactory.java License: GNU General Public License v2.0 | 5 votes |
/** * Construct a socket that interposes on a socket to match and replace. * @param socket the underlying socket * @param triggerBytes array of bytes to enable matching * @param matchBytes the bytes that must match * @param replaceBytes the replacement bytes */ public InterposeSocket(Socket socket, byte[] triggerBytes, byte[] matchBytes, byte[] replaceBytes) { this.socket = socket; this.triggerBytes = Objects.requireNonNull(triggerBytes, "triggerBytes"); this.matchBytes = Objects.requireNonNull(matchBytes, "matchBytes"); this.replaceBytes = Objects.requireNonNull(replaceBytes, "replaceBytes"); this.inLogStream = new ByteArrayOutputStream(); this.outLogStream = new ByteArrayOutputStream(); this.name = "IS" + ++num + "::" + Thread.currentThread().getName() + ": " + socket.getLocalPort() + " < " + socket.getPort(); }
Example 8
Source Project: wasindoor File: AloneServer.java License: Apache License 2.0 | 5 votes |
public Client getSokect(String ip, int port) { Iterator<Client> it = this.getClients().iterator(); while (it.hasNext()) { Client c = it.next(); Socket s = c.getSocket(); if (s.getInetAddress().getHostAddress().equals(ip) && s.getPort() == port) { return c; } } return null; }
Example 9
Source Project: jlibmodbus File: ModbusSlaveConnectionTCP.java License: Apache License 2.0 | 5 votes |
ModbusSlaveConnectionTCP(Socket socket) throws ModbusIOException { try { this.socket = socket; transport = ModbusTransportFactory.createTCP(socket); clientInfo = new TcpClientInfo(new TcpParameters(socket.getInetAddress(), socket.getPort(), socket.getKeepAlive()), false); open(); } catch (Exception e) { throw new ModbusIOException(e); } }
Example 10
Source Project: lucene-solr File: SocketProxy.java License: Apache License 2.0 | 5 votes |
public Pump(String kind, Socket source, Socket dest) { super("SocketProxy-"+kind+"-" + source.getPort() + ":" + dest.getPort()); src = source; destination = dest; pause.set(new CountDownLatch(0)); }
Example 11
Source Project: openjdk-jdk9 File: TestSocketFactory.java License: GNU General Public License v2.0 | 5 votes |
public InterposeSocket(Socket socket, byte[] matchBytes, byte[] replaceBytes) { this.socket = socket; this.matchBytes = Objects.requireNonNull(matchBytes, "matchBytes"); this.replaceBytes = Objects.requireNonNull(replaceBytes, "replaceBytes"); this.inLogStream = new ByteArrayOutputStream(); this.outLogStream = new ByteArrayOutputStream(); this.name = "IS" + ++num + "::" + Thread.currentThread().getName() + ": " + socket.getLocalPort() + " < " + socket.getPort(); }
Example 12
Source Project: TencentKona-8 File: IOEvent.java License: GNU General Public License v2.0 | 4 votes |
private static String getAddress(Socket s) { return s.getInetAddress().toString() + ":" + s.getPort(); }
Example 13
Source Project: freehealth-connector File: ExchangeImpl.java License: GNU Affero General Public License v3.0 | 4 votes |
public InetSocketAddress getRemoteAddress() { Socket s = this.connection.getChannel().socket(); InetAddress ia = s.getInetAddress(); int port = s.getPort(); return new InetSocketAddress(ia, port); }
Example 14
Source Project: activemq-artemis File: SocketProxy.java License: Apache License 2.0 | 4 votes |
public Pump(Socket source, Socket dest) { super("SocketProxy-DataTransfer-" + source.getPort() + ":" + dest.getPort()); src = source; destination = dest; pause.set(new CountDownLatch(0)); }
Example 15
Source Project: crate File: MockTcpTransport.java License: Apache License 2.0 | 4 votes |
public void accept(Executor executor) throws IOException { while (isOpen.get()) { Socket incomingSocket = serverSocket.accept(); MockChannel incomingChannel = null; try { configureSocket(incomingSocket); synchronized (this) { if (isOpen.get()) { incomingChannel = new MockChannel(incomingSocket, new InetSocketAddress( incomingSocket.getLocalAddress(), incomingSocket.getPort() ), profile); MockChannel finalIncomingChannel = incomingChannel; incomingChannel.addCloseListener(new ActionListener<Void>() { @Override public void onResponse(Void aVoid) { workerChannels.remove(finalIncomingChannel); } @Override public void onFailure(Exception e) { workerChannels.remove(finalIncomingChannel); } }); serverAcceptedChannel(incomingChannel); //establish a happens-before edge between closing and accepting a new connection workerChannels.add(incomingChannel); // this spawns a new thread immediately, so OK under lock incomingChannel.loopRead(executor); // the channel is properly registered and will be cleared by the close code. incomingSocket = null; incomingChannel = null; } } } finally { // ensure we don't leak sockets and channels in the failure case. Note that we null both // if there are no exceptions so this becomes a no op. IOUtils.closeWhileHandlingException(incomingSocket, incomingChannel); } } }
Example 16
Source Project: OpenAs2App File: AS2ReceiverHandler.java License: BSD 2-Clause "Simplified" License | 4 votes |
public String getClientInfo(Socket s) { return " " + s.getInetAddress().getHostAddress() + " " + s.getPort(); }
Example 17
Source Project: zap-extensions File: WebSocketEventPublisher.java License: Apache License 2.0 | 4 votes |
private String socketToStr(Socket socket) { if (socket == null) { return ""; } return socket.getLocalAddress().toString() + ":" + socket.getPort(); }
Example 18
Source Project: pooled-jms File: SocketProxy.java License: Apache License 2.0 | 4 votes |
public Pump(Socket source, Socket dest) { super("SocketProxy-DataTransfer-" + source.getPort() + ":" + dest.getPort()); src = source; destination = dest; pause.set(new CountDownLatch(0)); }
Example 19
Source Project: gemfirexd-oss File: HandShake.java License: Apache License 2.0 | 2 votes |
/** * Return fake, temporary DistributedMember to represent the other vm this * vm is connecting to * * @param sock the socket this handshake is operating on * @return temporary id to reprent the other vm */ private DistributedMember getDistributedMember(Socket sock) { return new InternalDistributedMember( sock.getInetAddress(), sock.getPort(), false); }
Example 20
Source Project: gemfirexd-oss File: HandShake.java License: Apache License 2.0 | 2 votes |
/** * Return fake, temporary DistributedMember to represent the other vm this * vm is connecting to * * @param sock the socket this handshake is operating on * @return temporary id to reprent the other vm */ private DistributedMember getDistributedMember(Socket sock) { return new InternalDistributedMember( sock.getInetAddress(), sock.getPort(), false); }