DatagramSocket isConnected - 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 isConnected 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, disconnect, isConnected
	 */ 
	public void dispose() { 
		isRunning = false;
		_myThread = null;
		if (_myDatagramSocket != null) {
			if (_myDatagramSocket.isConnected()) {
				Logger.printDebug("UdpServer.dispose()", "disconnect()"); 
				_myDatagramSocket.disconnect();
			} 
			Logger.printDebug("UdpServer.dispose()", "close()"); 
			_myDatagramSocket.close();
			_myDatagramSocket = null;
			Logger.printDebug("UdpServer.dispose()", 
					"Closing unicast datagram socket."); 
		} 
	} 
 
	/** 
	 * send a byte array to a previously defined remoteAddress. 
	 *  
5
CodeRank
This code example shows how to use the following methods:disconnect, isClosed, isConnected
        socket.setSoTimeout(timeout);
    } 
 
    private void disconnect() { 
         
       if (null != socket && socket.isConnected()) { 
           socket.disconnect();
       } 
         
       if (null != socket && !socket.isClosed()) {
           socket.close();
       } 
         
    } 
 
    public int readDataBlock(byte[] buf) throws IOException {
        //send trigger data 
        socket.send(trigger_packet);
        //receive data 
        DatagramPacket packet = new DatagramPacket(buf, buf.length, drone_addr, data_port);
5
CodeRank
This code example shows how to use the following methods:close, disconnect, isConnected
This code example shows how to use the following methods:close, disconnect, isConnected
This code example shows how to use the following methods:close, disconnect, isConnected
	 */ 
	public void close() { 
		try { 
 
			// 关闭接收套接字 
			if (receiveSocket.isConnected()) {
				receiveSocket.disconnect();
				receiveSocket.close();
			} 
 
			// 关闭发送套接字 
			if (sendSocket.isConnected()) {
				sendSocket.disconnect();
				sendSocket.close();
			} 
		} catch (Exception ex) {
			ex.printStackTrace();
		} 
	} 
} 
5
CodeRank
This code example shows how to use the following methods:close, disconnect, isConnected
This code example shows how to use the following methods:close, isClosed, isConnected
		public packetSender(DatagramPacket pack){
			this.packet=pack;
		} 
		public void run() { 
			try{ 
				if((socket==null)||(!socket.isConnected())||(socket.isClosed())){
					if((!(socket==null))&&(!(socket.isClosed())))
					{Log.d("closing", "socket");
					socket.close();}
					socket=null;
					socket=new DatagramSocket();//port binding not required as not listening here
				} 
				socket.send(packet);
				socket.close();
			} 
			 
			catch(SocketException e){
				Log.d("error","Socket conn error");
				e.printStackTrace();
			} catch (IOException e) {
5
CodeRank
isConnected Method Overview
Returns true if this datagram socket is connected to a remote address.
See Code Examples for other Java 8 DatagramSocket Methods: