Tabnine Logo
Socket.bind
Code IndexAdd Tabnine to your IDE (free)

How to use
bind
method
in
java.net.Socket

Best Java code snippets using java.net.Socket.bind (Showing top 20 results out of 5,418)

Refine searchRefine arrow

  • Socket.connect
  • InetSocketAddress.<init>
origin: stackoverflow.com

 Socket s = new Socket();
s.bind(new InetSocketAddress("172.16.1.102", 5000));
s.connect(new InetSocketAddress("google.com", 80));
origin: apache/activemq

@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();
}
origin: org.apache.hadoop/hadoop-common

  "Local address %s must be of same family as remote address %s.",
  localAddr, endpoint);
socket.bind(localAddr);
if (ch == null) {
 socket.connect(endpoint, timeout);
} else {
 SocketIOWithTimeout.connect(ch, endpoint, timeout);
origin: org.apache.hadoop/hadoop-common

@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;
}
origin: apache/activemq

  @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();
  }
};
origin: stackoverflow.com

delegate.bind(localAddr);
delegate.connect(remoteAddr);
delegate.connect(remoteAddr, timeout);
origin: org.apache.hadoop/hadoop-common

@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;
}
origin: Qihoo360/XLearning

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");
}
origin: stackoverflow.com

delegate.bind(localAddr);
delegate.connect(remoteAddr);
delegate.connect(remoteAddr, timeout);
origin: apache/nifi

@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;
}
origin: spotify/helios

 s.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), port));
} catch (IOException e) {
 return false;
origin: stackoverflow.com

delegate.bind(localAddr);
delegate.connect(remoteAddr);
delegate.connect(remoteAddr, timeout);
origin: internetarchive/heritrix3

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;
}
origin: apache/ignite

/**
 * 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;
  }
}
origin: org.apache.hadoop/hadoop-common

@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;
}
origin: wildfly/wildfly

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;
  }
}
origin: internetarchive/heritrix3

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;
}         

origin: jphp-group/jphp

@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;
}
origin: org.apache.hadoop/hadoop-common

@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;
}
origin: wildfly/wildfly

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;
  }
}
java.netSocketbind

Javadoc

Binds this socket to the given local host address and port specified by the SocketAddress localAddr. If localAddr is set to null, this socket will be bound to an available local address on any free port.

Popular methods of Socket

  • close
    Closes the socket. It is not possible to reconnect or rebind to this socket thereafter which means a
  • <init>
    Creates an unconnected socket with the given socket implementation.
  • getOutputStream
    Returns an output stream to write data into this socket.
  • getInputStream
    Returns an input stream to read data from this socket.
  • connect
    Connects this socket to the given remote host address and port specified by the SocketAddress remote
  • setSoTimeout
    Sets this socket's SocketOptions#SO_TIMEOUT in milliseconds. Use 0 for no timeout. To take effect, t
  • getInetAddress
    Returns the IP address of the target host this socket is connected to, or null if this socket is not
  • setTcpNoDelay
    Sets this socket's SocketOptions#TCP_NODELAY option.
  • getPort
    Returns the port number of the target host this socket is connected to, or 0 if this socket is not y
  • isClosed
    Returns whether this socket is closed.
  • getRemoteSocketAddress
    Returns the remote address and port of this socket as a SocketAddress or null if the socket is not c
  • setKeepAlive
    Sets this socket's SocketOptions#SO_KEEPALIVE option.
  • getRemoteSocketAddress,
  • setKeepAlive,
  • isConnected,
  • setSoLinger,
  • setSendBufferSize,
  • setReceiveBufferSize,
  • getLocalAddress,
  • getLocalPort,
  • shutdownOutput

Popular in Java

  • Making http post requests using okhttp
  • getContentResolver (Context)
  • getExternalFilesDir (Context)
  • putExtra (Intent)
  • ObjectMapper (com.fasterxml.jackson.databind)
    ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Pl
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • Comparator (java.util)
    A Comparator is used to compare two objects to determine their ordering with respect to each other.
  • NoSuchElementException (java.util)
    Thrown when trying to retrieve an element past the end of an Enumeration or Iterator.
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • JList (javax.swing)
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now