Refine search
Socket s = new Socket(); s.bind(new InetSocketAddress("172.16.1.102", 5000)); s.connect(new InetSocketAddress("google.com", 80));
@Override public Socket createSocket(String address, int port, InetAddress localAddresss, int localPort) throws IOException, UnknownHostException { SocketChannel channel = SocketChannel.open(); channel.socket().bind(new InetSocketAddress(localAddresss, localPort)); channel.connect(new InetSocketAddress(address, port)); return channel.socket(); }
@Override public Socket createSocket(String host, int port, InetAddress localHostAddr, int localPort) throws IOException, UnknownHostException { Socket socket = createSocket(); socket.bind(new InetSocketAddress(localHostAddr, localPort)); socket.connect(new InetSocketAddress(host, port)); return socket; }
@Override public Socket createSocket(InetAddress address, int port, InetAddress localAddresss, int localPort) throws IOException { SocketChannel channel = SocketChannel.open(); channel.socket().bind(new InetSocketAddress(localAddresss, localPort)); channel.connect(new InetSocketAddress(address, port)); return channel.socket(); } };
@Override public Socket createSocket(String host, int port, InetAddress localHostAddr, int localPort) throws IOException, UnknownHostException { Socket socket = createSocket(); socket.bind(new InetSocketAddress(localHostAddr, localPort)); socket.connect(new InetSocketAddress(host, port)); return socket; }
public static void getReservePort(Socket socket, String localHost, int reservePortBegin, int reservePortEnd) throws IOException { int i = 0; Random random = new Random(System.currentTimeMillis()); while (i < 1000) { int rand = random.nextInt(reservePortEnd - reservePortBegin); try { socket.bind(new InetSocketAddress(localHost, reservePortBegin + rand)); return; } catch (IOException e) { try { Thread.sleep(1000); } catch (InterruptedException e2) {} } } throw new IOException("couldn't allocate a unused port"); }
@Override public Socket createSocket(InetAddress addr, int port, InetAddress localHostAddr, int localPort) throws IOException { Socket socket = createSocket(); socket.bind(new InetSocketAddress(localHostAddr, localPort)); socket.connect(new InetSocketAddress(addr, port)); return socket; }
s.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), port)); } catch (IOException e) { return false;
public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException, UnknownHostException { Socket sock = createSocket(); sock.bind(new InetSocketAddress(localHost, localPort)); sock.connect(new InetSocketAddress(host, port), connectTimeoutMs); return sock; }
/** * Creates socket binding it to a local host address. This operation is not blocking. * * @return Created socket. * @throws IOException If failed. */ Socket createSocket() throws IOException { Socket sock = null; try { if (isSslEnabled()) sock = sslSockFactory.createSocket(); else sock = new Socket(); sock.bind(new InetSocketAddress(locHost, 0)); sock.setTcpNoDelay(true); return sock; } catch (IOException e) { if (sock != null) U.closeQuiet(sock); throw e; } }
@Override public Socket createSocket(InetAddress addr, int port, InetAddress localHostAddr, int localPort) throws IOException { Socket socket = createSocket(); socket.bind(new InetSocketAddress(localHostAddr, localPort)); socket.connect(new InetSocketAddress(addr, port)); return socket; }
public static void bind(Socket sock, InetAddress bind_addr, int start_port, int end_port) throws Exception { int original_start_port=start_port; while(true) { try { InetSocketAddress sock_addr=new InetSocketAddress(bind_addr, start_port); sock.bind(sock_addr); } catch(SocketException bind_ex) { if(start_port == end_port) throw new BindException("No available port to bind to in range [" + original_start_port + " .. " + end_port + "]"); if(bind_addr != null && !bind_addr.isLoopbackAddress()) { NetworkInterface nic=NetworkInterface.getByInetAddress(bind_addr); if(nic == null) throw new BindException("bind_addr " + bind_addr + " is not a valid interface: " + bind_ex); } start_port++; continue; } break; } }
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException { Socket sock = createSocket(); sock.bind(new InetSocketAddress(localAddress, localPort)); sock.connect(new InetSocketAddress(address, port), connectTimeoutMs); return sock; }
@Signature({@Arg("hostname"), @Arg("port")}) public Memory bind(Environment env, Memory... args) throws IOException { socket.bind(new InetSocketAddress(args[0].toString(), args[1].toInteger())); return Memory.NULL; }
@Override public Socket createSocket(InetAddress addr, int port, InetAddress localHostAddr, int localPort) throws IOException { Socket socket = createSocket(); socket.bind(new InetSocketAddress(localHostAddr, localPort)); socket.connect(new InetSocketAddress(addr, port)); return socket; }
protected void connect(Address dest, boolean send_local_addr) throws Exception { SocketAddress destAddr=new InetSocketAddress(((IpAddress)dest).getIpAddress(), ((IpAddress)dest).getPort()); try { if(!server.defer_client_binding) this.sock.bind(new InetSocketAddress(server.client_bind_addr, server.client_bind_port)); Util.connect(this.sock, destAddr, server.sock_conn_timeout); if(this.sock.getLocalSocketAddress() != null && this.sock.getLocalSocketAddress().equals(destAddr)) throw new IllegalStateException("socket's bind and connect address are the same: " + destAddr); this.out=new DataOutputStream(createBufferedOutputStream(sock.getOutputStream())); this.in=new DataInputStream(createBufferedInputStream(sock.getInputStream())); connected=sock.isConnected(); if(send_local_addr) sendLocalAddress(server.localAddress()); } catch(Exception t) { Util.close(this.sock); connected=false; throw t; } }