Package java.net

Examples of java.net.Socket.bind()


    Socket theSocket2 = new Socket();
    try {
      theAddress = new InetSocketAddress(InetAddress.getLocalHost(),
          Support_PortManager.getNextPort());
      theSocket.bind(theAddress);
      theSocket2.bind(theAddress);
      fail("No exception binding to address that is not available");
    } catch (IOException ex) {
    }
    theSocket.close();
    theSocket2.close();
View Full Code Here


        Socket socket = new Socket(proxy);

        try {
            InetAddress address = InetAddress.getByName("localhost");
            int port = 0;
            socket.bind(new InetSocketAddress(address, port));
           
            assertEquals(address, socket.getLocalAddress());
            assertTrue(port!=socket.getLocalPort());

        } finally {
View Full Code Here

        InetSocketAddress theOtherLocalAddress = new InetSocketAddress(
            (InetAddress) allAddresses[0], theLocalAddress
                .getPort());
        Socket theSocket = new Socket();
        theSocket.setReuseAddress(false);
        theSocket.bind(theLocalAddress);
        Socket theSocket2 = null;
        String platform = System.getProperty("os.name");
        try {
          theSocket2 = new Socket();
          theSocket2.setReuseAddress(false);
View Full Code Here

        Socket theSocket2 = null;
        String platform = System.getProperty("os.name");
        try {
          theSocket2 = new Socket();
          theSocket2.setReuseAddress(false);
          theSocket2.bind(theOtherLocalAddress);

          if ((!platform.startsWith("Linux"))
              && ((!platform.startsWith("Windows")) ||
              // for windows we don't get an exception with
              // setreuse set to false unless one of the
View Full Code Here

        theSocket.setReuseAddress(true);
        theSocket.bind(theLocalAddress);
        try {
          theSocket2 = new Socket();
          theSocket2.setReuseAddress(true);
          theSocket2.bind(theOtherLocalAddress);
          theSocket2.close();
        } catch (IOException ex) {
          fail("IOException when setReuseAddress is true and we bind :"
              + ex.toString());
        }
View Full Code Here

        theSocket = new Socket();
        theSocket.bind(theLocalAddress);
        try {
          theSocket2 = new Socket();
          theSocket2.bind(theOtherLocalAddress);
          theSocket2.close();
          if ((!platform.startsWith("Linux"))
              && ((!platform.startsWith("Windows")) || !((((InetAddress) allAddresses[0]) instanceof Inet4Address) && (((InetAddress) allAddresses[1]) instanceof Inet4Address)))) {
            fail("No exception when setReuseAddress is default and we bind:"
                + theLocalAddress.toString()
View Full Code Here

            return createSocket(host, port, localAddress, localPort);
        } else {
            Socket socket = factory.createSocket();
            SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
            SocketAddress remoteaddr = new InetSocketAddress(host, port);
            socket.bind(localaddr);
            socket.connect(remoteaddr, timeout);
            return socket;
        }
    }
View Full Code Here

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

  /* @inheritDoc */
 
View Full Code Here

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

  /* @inheritDoc */
 
View Full Code Here

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

  /* @inheritDoc */
 
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.