Package java.net

Examples of java.net.DatagramSocket.bind()


            throw new UnresolvedAddressException();
        }

        final DatagramSocket socket = channel.socket();
        try {
            socket.bind(inetLocal);
        } catch (SocketException e) {
            if (socket.isBound()) {
                throw Util.initCause(new AlreadyBoundException(), e);
            }
            if (socket.isClosed()) {
View Full Code Here


      // now make sure that datagrams sent from this socket appear to come
      // from the address we bound to
      InetAddress localHost = InetAddress.getLocalHost();
      portNumber = ports[2];
      DatagramSocket ds = new DatagramSocket(null);
      ds.bind(new InetSocketAddress(localHost, portNumber));

      try {
        server = new DatagramServer(serverPortNumber, localHost);
        server.start();
        Thread.sleep(1000);
View Full Code Here

      DatagramSocket theSocket2 = new DatagramSocket(ports[0]);
      try {
        InetSocketAddress theAddress = new InetSocketAddress(
            InetAddress.getLocalHost(), ports[1]);
        theSocket.bind(theAddress);
        theSocket2.bind(theAddress);
        fail("No exception binding to address that is not available");
      } catch (SocketException ex) {
      }
      theSocket.close();
      theSocket2.close();
View Full Code Here

      InetSocketAddress theLocalAddress = new InetSocketAddress(
          InetAddress.getLocalHost(), ports[2]);
      theSocket = new DatagramSocket(null);
      assertFalse("Socket indicated bound when it should not be (2)",
          theSocket.isBound());
      theSocket.bind(theLocalAddress);
      assertTrue("Socket indicated not bound when it should be (4)",
          theSocket.isBound());
      theSocket.close();
      assertTrue("Socket indicated not bound when it should be (5)",
          theSocket.isBound());
View Full Code Here

      // now create one that is not connected and validate that we get the
      // right answer
      DatagramSocket theSocket = new DatagramSocket(null);
      portNumber = ports[2];
      theSocket.bind(new InetSocketAddress(InetAddress.getLocalHost(),
          portNumber));
      assertNull(
          "Returned incorrect InetSocketAddress -unconnected socket:"
              + "Expected: NULL", theSocket
              .getRemoteSocketAddress());
View Full Code Here

          "Returned incorrect InetSocketAddress -unbound socket- Expected null",
          theSocket.getLocalSocketAddress());

      // now bind the socket and make sure we get the right answer
      portNumber = Support_PortManager.getNextPortForUDP();
      theSocket.bind(new InetSocketAddress(InetAddress.getLocalHost(),
          portNumber));
      assertTrue("Returned incorrect InetSocketAddress(2):"
          + theSocket.getLocalSocketAddress().toString()
          + "Expected: "
          + (new InetSocketAddress(InetAddress.getLocalHost(),
View Full Code Here

        theSocket1 = new DatagramSocket(null);
        theSocket2 = new DatagramSocket(null);
        theSocket1.setReuseAddress(false);
        theSocket2.setReuseAddress(false);
        theSocket1.bind(theAddress);
        theSocket2.bind(theAddress);
        fail(
            "No exception when trying to connect to do duplicate socket bind with re-useaddr set to false");
      } catch (BindException e) {

      }
View Full Code Here

        theSocket1 = new DatagramSocket(null);
        theSocket2 = new DatagramSocket(null);
        theSocket1.setReuseAddress(true);
        theSocket2.setReuseAddress(true);
        theSocket1.bind(theAddress);
        theSocket2.bind(theAddress);
      } catch (Exception e) {
        fail(
            "unexpected exception when trying to connect to do duplicate socket bind with re-useaddr set to true");
      }
      if (theSocket1 != null)
View Full Code Here

            InetAddress.getLocalHost(), Support_PortManager
                .getNextPortForUDP());
        theSocket1 = new DatagramSocket(null);
        theSocket2 = new DatagramSocket(null);
        theSocket1.bind(theAddress);
        theSocket2.bind(theAddress);
        fail(
            "No exception when trying to connect to do duplicate socket bind with re-useaddr left as default");
      } catch (BindException e) {

      }
View Full Code Here

            if (socketChannel instanceof SocketChannel) {
                Socket socket = ((SocketChannel)socketChannel).socket();
                socket.bind(iaddr);
            } else if (socketChannel instanceof DatagramChannel) {
                DatagramSocket socket = ((DatagramChannel)socketChannel).socket();
                socket.bind(iaddr);
            } else {
                throw getRuntime().newErrnoENOPROTOOPTError();
            }
        } catch(UnknownHostException e) {
            throw sockerr(context.getRuntime(), "bind(2): unknown host");
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.