DatagramSocket setReuseAddress - 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 setReuseAddress method.

This code example shows how to use the following methods:close, setReuseAddress
			ServerSocket ss = null;
			DatagramSocket ds = null;
			try { 
				ss = new ServerSocket(port);
				ss.setReuseAddress(true);
				ds = new DatagramSocket(port);
				ds.setReuseAddress(true);
				return true; 
			} catch (IOException e) {
			} finally { 
				if (ds != null) {
					ds.close();
				} 
 
				if (ss != null) {
					try { 
						ss.close();
					} catch (IOException e) {
						/* should not be thrown */ 
					} 
6
CodeRank
This code example shows how to use the following methods:close, setReuseAddress
        ServerSocket ss = null;
        DatagramSocket ds = null;
        try { 
            ss = new ServerSocket(port);
            ss.setReuseAddress(true);
            ds = new DatagramSocket(port);
            ds.setReuseAddress(true);
            return true; 
        } catch (IOException e) {
            // do nothing 
        } finally { 
            if (ds != null) {
                ds.close();
            } 
            if (ss != null) {
                try { 
                    ss.close();
                } catch (IOException e) {
                    /* should not be thrown */ 
                } 
7
CodeRank
This code example shows how to use the following methods:close, setReuseAddress
 
    try { 
      ss = new ServerSocket(port);
      ss.setReuseAddress(true);
 
      ds = new DatagramSocket(port);
      ds.setReuseAddress(true);
 
      return true; 
 
    } catch (IOException e) {
      return false; 
    } finally { 
      if (ss != null) {
        ss.close();
      } 
 
      if (ds != null) {
        ds.close();
      } 

6
CodeRank
This code example shows how to use the following methods:close, send, setReuseAddress, setSendBufferSize
	 
	@Override 
	protected DatagramSocket doInBackground(Bitmap... params) {
		this.bitmap = params[0];
		try { 
			socket = new DatagramSocket();
			socket.setReuseAddress(true);
			int size = this.bitmap.getByteCount();
			 
			Log.d(TAG, "Size:" + size);
			this.stream = new ByteArrayOutputStream();
			this.bitmap.compress(CompressFormat.JPEG, 50, stream);
			socket.setSendBufferSize(stream.size());
			DatagramPacket pk = new DatagramPacket(stream.toByteArray(), stream.size(),InetAddress.getByName(ipAddress),9998);
			socket.send(pk);
			socket.close();
			stream.close();
			 
			 
			/*DatagramPacket pk = new DatagramPacket(data, data.length,InetAddress.getByName(ipAddress),9999); 
			Log.d(TAG, "Packet sending"); 
6
CodeRank
This code example shows how to use the following methods:setBroadcast, setReuseAddress, setSoTimeout
 
	protected abstract int getInterfaceAddress(); 
 
	@Override 
	protected void PreRun() throws Exception { 
		socket = new DatagramSocket(getPort(), InetAddress.getByAddress(IP
				.IntToBytes(getInterfaceAddress()))); 
		socket.setBroadcast(true);
		socket.setReuseAddress(true);
		socket.setSoTimeout(100);
	} 
 
	@Override 
	protected void PostRun() throws Exception { 
		if (socket != null) {
			socket.close();
			socket = null;
		} 
	} 
 
6
CodeRank
This code example shows how to use the following methods:bind, getLocalPort, setReceiveBufferSize, setReuseAddress, setSoTimeout
			dgSocket=new DatagramSocket(localPort, localAddress); 
		}else{ 
			dgSocket=new DatagramSocket(localPort); 
		} 
		*/ 
	    dgSocket = new DatagramSocket(null);
	    dgSocket.setReuseAddress(true);
	    dgSocket.bind(new InetSocketAddress(localAddress, localPort));
	     
		if(localPort>0)this.port = localPort;
		else port=dgSocket.getLocalPort();
		 
		//set a time out to avoid blocking in doReceive() 
		dgSocket.setSoTimeout(30 * 1000);
		//buffer size 
		dgSocket.setReceiveBufferSize(128*1024);
	} 
 
	/** 
	 * bind to the default network interface on the machine 
	 *  
6
CodeRank
This code example shows how to use the following methods:close, setReuseAddress
        ServerSocket ss = null;
        DatagramSocket ds = null;
        try { 
            ss = new ServerSocket(port);
            ss.setReuseAddress(true);
            ds = new DatagramSocket(port);
            ds.setReuseAddress(true);
            return true; 
        } catch (IOException e) {
            // Do nothing 
        } finally { 
            if (ds != null) {
                ds.close();
            } 
 
            if (ss != null) {
                try { 
                    ss.close();
                } catch (IOException e) {
                    /* should not be thrown */ 
6
CodeRank
This code example shows how to use the following methods:close, setReuseAddress
        DatagramSocket ds = null;
        try 
        { 
            ss = new ServerSocket( port );
            ss.setReuseAddress( true );
            ds = new DatagramSocket( port );
            ds.setReuseAddress( true );
            return true; 
        } 
        catch ( IOException e )
        { 
        } 
        finally 
        { 
            if ( ds != null )
            { 
                ds.close();
            } 
 
            if ( ss != null )

5
CodeRank
This code example shows how to use the following methods:close, setReuseAddress
        if (connectionType.equalsIgnoreCase("tcp://") || connectionType.equalsIgnoreCase("ssl://")) {
 
            DatagramSocket ds = null;
 
            try { 
                ds = new DatagramSocket(port);
                ds.setReuseAddress(true);
 
                return true; 
            } catch (IOException e) {
                log.error(e);
            } finally { 
                if (ds != null) {
                    ds.close();
                } 
            } 
        } 
 
        //check for http and https port availability 
        if (connectionType.equalsIgnoreCase("http://") || connectionType.equalsIgnoreCase("https://")) {
5
CodeRank
This code example shows how to use the following methods:close, setReuseAddress
        ServerSocket ss = null;
        DatagramSocket ds = null;
        try { 
            ss = new ServerSocket(port);
            ss.setReuseAddress(true);
            ds = new DatagramSocket(port);
            ds.setReuseAddress(true);
            return true; 
        } catch (IOException e) {
            // Do nothing 
        } finally { 
            if (ds != null) {
                ds.close();
            } 
 
            if (ss != null) {
                try { 
                    ss.close();
                } catch (IOException e) {
                    /* should not be thrown */ 
5
CodeRank

Related DatagramSocket setReuseAddress Questions & Answers:

setReuseAddress Method Overview
Sets the socket option SocketOptions.SO_REUSEADDR.
See Code Examples for other Java 8 DatagramSocket Methods: