DatagramSocket isBound - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for DatagramSocket isBound method.

This code example shows how to use the following methods:connect, isBound, isConnected
/** 
 * A simple test designed to conduct a DTLS handshake with an external DTLS server. 
 * <p/> 
 * Please refer to GnuTLSSetup.txt or OpenSSLSetup.txt, and x509-*.pem files in this package for 
 * help configuring an external DTLS server. 
 */ 
public class DTLSClientTest 
{ 
    private static final SecureRandom secureRandom = new SecureRandom();
 
    public static void main(String[] args)
        throws Exception 
    { 
        InetAddress address = InetAddress.getLocalHost();
        int port = 5556;
 
        TlsSession session = createSession(address, port);
 
        MockDTLSClient client = new MockDTLSClient(session);
 

7
CodeRank
This code example shows how to use the following methods:isBound, isConnected, joinGroup
 
	public synchronized void connect() throws IOException { 
		if (_socket == null) {
			_socket = new MulticastSocket(_port);
		} 
		else if (_socket.isConnected() && _socket.isBound()) {
			return; 
		} 
 
		_address = InetAddress.getByName(_host);
 
		_socket.joinGroup(_address);
 
		_connected = true;
 
		start();
	} 
 
	public synchronized void disconnect() { 
 
6
CodeRank
This code example shows how to use the following methods:isBound, isConnected
    protected final int receiveLimit, sendLimit;
 
    public UDPTransport(DatagramSocket socket, int mtu)
        throws IOException 
    { 
        if (!socket.isBound() || !socket.isConnected())
        { 
            throw new IllegalArgumentException("'socket' must be bound and connected");
        } 
 
        this.socket = socket;
 
        // NOTE: As of JDK 1.6, can use NetworkInterface.getMTU 
 
        this.receiveLimit = mtu - MIN_IP_OVERHEAD - UDP_OVERHEAD;
        this.sendLimit = mtu - MAX_IP_OVERHEAD - UDP_OVERHEAD;
    } 
 
    public int getReceiveLimit() 
    { 
6
CodeRank
This code example shows how to use the following methods:close, isBound, isClosed, isConnected, getLoopbackMode
        MulticastSocket s = new MulticastSocket(addr);
        assertTrue(s.getReuseAddress());
    } 
 
    public void test_getLoopbackMode() throws Exception { 
        MulticastSocket ms = new MulticastSocket((SocketAddress) null);
        assertTrue("should not be bound", !ms.isBound() && !ms.isClosed() && !ms.isConnected());
        ms.getLoopbackMode();
        assertTrue("should not be bound", !ms.isBound() && !ms.isClosed() && !ms.isConnected());
        ms.close();
        assertTrue("should be closed", ms.isClosed());
    } 
 
    public void test_setLoopbackModeZ() throws Exception { 
        MulticastSocket ms = new MulticastSocket();
        ms.setLoopbackMode(true);
        assertTrue("loopback should be true", ms.getLoopbackMode());
        ms.setLoopbackMode(false);
        assertTrue("loopback should be false", !ms.getLoopbackMode());
        ms.close();
5
CodeRank
This code example shows how to use the following methods:isBound, isClosed
    protected boolean work() 
    { 
        // Check state before doing work 
        if (mSocket == null)
            return false; 
        if (!mSocket.isBound())
            return false; 
        if (mSocket.isClosed())
            return false; 
 
        try 
        { 
            return sendPacket(mPacketSendQueue.take());
        } 
        catch (InterruptedException e)
        { 
            return false; 
        } 
    } 
 
4
CodeRank
This code example shows how to use the following methods:bind, close, isBound, isClosed, isConnected
 
	/** 
	 * @tests java.net.MulticastSocket#MulticastSocket(java.net.SocketAddress) 
	 */ 
	public void test_ConstructorLjava_net_SocketAddress() throws Exception {	 
		MulticastSocket ms = new MulticastSocket((SocketAddress) null);
        assertTrue("should not be bound", !ms.isBound() && !ms.isClosed()
                && !ms.isConnected());
        ms.bind(new InetSocketAddress(InetAddress.getLocalHost(),
                Support_PortManager.getNextPortForUDP())); 
        assertTrue("should be bound", ms.isBound() && !ms.isClosed()
                && !ms.isConnected());
        ms.close();
        assertTrue("should be closed", ms.isClosed());
        ms = new MulticastSocket(new InetSocketAddress(InetAddress
                .getLocalHost(), Support_PortManager.getNextPortForUDP()));
        assertTrue("should be bound", ms.isBound() && !ms.isClosed()
                && !ms.isConnected());
        ms.close();
        assertTrue("should be closed", ms.isClosed());
4
CodeRank
This code example shows how to use the following methods:bind, close, isBound, isClosed, isConnected
 
	/** 
	 * @tests java.net.MulticastSocket#MulticastSocket(java.net.SocketAddress) 
	 */ 
	public void test_ConstructorLjava_net_SocketAddress() throws Exception {	 
		MulticastSocket ms = new MulticastSocket((SocketAddress) null);
        assertTrue("should not be bound", !ms.isBound() && !ms.isClosed()
                && !ms.isConnected());
        ms.bind(new InetSocketAddress(InetAddress.getLocalHost(),
                Support_PortManager.getNextPortForUDP())); 
        assertTrue("should be bound", ms.isBound() && !ms.isClosed()
                && !ms.isConnected());
        ms.close();
        assertTrue("should be closed", ms.isClosed());
        ms = new MulticastSocket(new InetSocketAddress(InetAddress
                .getLocalHost(), Support_PortManager.getNextPortForUDP()));
        assertTrue("should be bound", ms.isBound() && !ms.isClosed()
                && !ms.isConnected());
        ms.close();
        assertTrue("should be closed", ms.isClosed());
4
CodeRank
This code example shows how to use the following methods:bind, close, isBound, isClosed, isConnected
 
	/** 
	 * @tests java.net.MulticastSocket#MulticastSocket(java.net.SocketAddress) 
	 */ 
	public void test_ConstructorLjava_net_SocketAddress() throws Exception {	 
		MulticastSocket ms = new MulticastSocket((SocketAddress) null);
        assertTrue("should not be bound", !ms.isBound() && !ms.isClosed()
                && !ms.isConnected());
        ms.bind(new InetSocketAddress(InetAddress.getLocalHost(),
                Support_PortManager.getNextPortForUDP())); 
        assertTrue("should be bound", ms.isBound() && !ms.isClosed()
                && !ms.isConnected());
        ms.close();
        assertTrue("should be closed", ms.isClosed());
        ms = new MulticastSocket(new InetSocketAddress(InetAddress
                .getLocalHost(), Support_PortManager.getNextPortForUDP()));
        assertTrue("should be bound", ms.isBound() && !ms.isClosed()
                && !ms.isConnected());
        ms.close();
        assertTrue("should be closed", ms.isClosed());
4
CodeRank
This code example shows how to use the following methods:isBound, joinGroup
        } 
        return remoteAddress;
    } 
 
    public boolean isBound() { 
        return isOpen() && socket.isBound();
    } 
 
    public boolean isConnected() { 
        return isOpen() && socket.isConnected();
    } 
 
    @Override 
    protected boolean setClosed() { 
        return super.setClosed(); 
    } 
 
    @Override 
    protected void setInterestOpsNow(int interestOps) {
        super.setInterestOpsNow(interestOps);

4
CodeRank
This code example shows how to use the following methods:isBound
      } 
   } 
 
   private void sendBroadcast(int port) {
      // broadcast the server host/port           
      if (broadcastSocket == null || !broadcastSocket.isBound()) {
         initBroadcastServer(); 
      } else { 
         // as an ode to the RPG programmers of yore, I use the tilde as a delimiter!  
         // (this sucks balls BTW) 
         // (and note we call "getWifiIpAddress" every time here, intentionally (in case it has changed)) 
         String wifiIpAddress = NetworkUtil.getWifiIpAddress(wifiManager);
         final String msg =
                  EMBIGGEN_HOST + DELIMITER + hostId + DELIMITER + wifiIpAddress + DELIMITER + port;
 
         broadcastExecutor.submit(new Runnable() {
            public void run() { 
               try { 
                  broadcastSocket.send(new DatagramPacket(msg.getBytes(), msg.getBytes().length, getBroadcastAddress(),
                           BROADCAST_FIXED_PORT));
4
CodeRank
isBound Method Overview
Returns true if this socket is bound to a local address.
See Code Examples for other Java 8 DatagramSocket Methods: