Package java.net

Examples of java.net.DatagramSocket.connect()


      theSocket.connect(new InetSocketAddress(addr, port));
      assertTrue("Socket indicated  not connected when it should be",
          theSocket.isConnected());

      // reconnect the socket and make sure we get the right answer
      theSocket.connect(new InetSocketAddress(addr, ports[2]));
      assertTrue("Socket indicated  not connected when it should be",
          theSocket.isConnected());

      // now disconnect the socket and make sure we get the right answer
      theSocket.disconnect();
View Full Code Here


          theSocket.isConnected());
      theSocket.close();

      // now check behavior when socket is closed when connected
      theSocket = new DatagramSocket(ports[3]);
      theSocket.connect(new InetSocketAddress(addr, port));
      theSocket.close();
      assertTrue("Socket indicated  not connected when it should be",
          theSocket.isConnected());
    } catch (Exception e) {
      fail("Got exception during isConnected tests" + e.toString());
View Full Code Here

      int[] ports = Support_PortManager.getNextPortsForUDP(3);
      int sport = ports[0];
      int portNumber = ports[1];
      DatagramSocket s = new DatagramSocket(new InetSocketAddress(
          InetAddress.getLocalHost(), portNumber));
      s.connect(new InetSocketAddress(InetAddress.getLocalHost(), sport));
      assertTrue("Returned incorrect InetSocketAddress(1):"
          + s.getLocalSocketAddress().toString(), s
          .getRemoteSocketAddress().equals(
              new InetSocketAddress(InetAddress.getLocalHost(),
                  sport)));
View Full Code Here

          "Returned incorrect InetSocketAddress -unconnected socket:"
              + "Expected: NULL", theSocket
              .getRemoteSocketAddress());

      // now connect and validate we get the right answer
      theSocket.connect(new InetSocketAddress(InetAddress.getLocalHost(),
          sport));
      assertTrue("Returned incorrect InetSocketAddress(2):"
          + theSocket.getRemoteSocketAddress().toString(), theSocket
          .getRemoteSocketAddress().equals(
              new InetSocketAddress(InetAddress.getLocalHost(),
View Full Code Here

      byte theBytes[] = { -1, -1, -1, -1 };

      // validate we cannot connect to the broadcast address when
      // setBroadcast is false
      try {
        theSocket.connect(new InetSocketAddress(InetAddress
            .getByAddress(theBytes), ports[1]));
        assertFalse(
            "No exception when connecting to broadcast address with setBroadcast(false)",
            theSocket.getBroadcast());
      } catch (Exception ex) {
View Full Code Here

      }

      // now validate that we can connect to the broadcast address when
      // setBroadcast is true
      theSocket.setBroadcast(true);
      theSocket
          .connect(new InetSocketAddress(InetAddress
              .getByAddress(theBytes), ports[2]));
      ensureExceptionThrownIfOptionIsUnsupportedOnOS(SO_BROADCAST);
    } catch (Exception e) {
      handleException(e, SO_BROADCAST);
View Full Code Here

      // Create a connected datagram socket to test
      // PlainDatagramSocketImpl.peek()
      InetAddress localHost = InetAddress.getLocalHost();
      DatagramSocket ds = new DatagramSocket();
      int port = ds.getLocalPort();
      ds.connect(localHost, port);
      DatagramPacket send = new DatagramPacket(new byte[10], 10,
          localHost, port);
      ds.send(send);
      DatagramPacket receive = new DatagramPacket(new byte[20], 20);
      ds.setSoTimeout(2000);
View Full Code Here

    // send a dgram to a server that is not running and then do a recv
    try {
      ds = new java.net.DatagramSocket();
      InetAddress inetAddress = InetAddress.getLocalHost();
      int portNumber = Support_PortManager.getNextPortForUDP();
      ds.connect(inetAddress, portNumber);
      DatagramPacket send = new DatagramPacket(new byte[10], 10);
      ds.send(send);
      DatagramPacket receive = new DatagramPacket(new byte[20], 20);
      ds.setSoTimeout(10000);
      ds.receive(receive);
View Full Code Here

      DatagramSocket theSocket = new DatagramSocket(portNumber);
      assertEquals("Expected -1 for remote port as not connected",
          -1, theSocket.getPort());

      // now connect the socket and validate that we get the right port
      theSocket.connect(InetAddress.getLocalHost(), portNumber);
      assertTrue("getPort returned wrong value:" + theSocket.getPort()
          + ":Expected:" + portNumber,
          theSocket.getPort() == portNumber);
    } catch (Exception e) {
      fail("unexpected exception during getPort test : " + e.getMessage());
View Full Code Here

        client.close();
    }

    public void testUDP() throws Exception {
        DatagramSocket client = new DatagramSocket();
        client.connect(new InetSocketAddress("127.0.0.1", port));
        client.setSoTimeout(500);

        byte[] writeBuf = new byte[16];
        byte[] readBuf = new byte[writeBuf.length];
        DatagramPacket wp = new DatagramPacket(writeBuf, writeBuf.length);
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.