Java 8 DatagramSocket - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 DatagramSocket class.

This code example shows how to use the following methods:
    @Test 
    public void createDatagram() throws IOException { 
 
        DatagramSocket socket1 = new DatagramSocket();
        DatagramSocket socket2 = new DatagramSocket();
        DatagramSocket socket3 = new DatagramSocket();
        DatagramSocket socket4 = new DatagramSocket();
        InetAddress localhost = InetAddress.getLocalHost();
        SocketAddress socketAddress = new InetSocketAddress(localhost, 1);
 
        when(this.factory.createDatagramSocket("test")).thenReturn(socket1);
        when(this.factory.createDatagramSocket("test", 1)).thenReturn(socket2);
        when(this.factory.createDatagramSocket("test", socketAddress)).thenReturn(socket3);
        when(this.factory.createDatagramSocket("test", 1, localhost)).thenReturn(socket4);
 
        DatagramSocket result1 = this.subject.createDatagramSocket("test");
        DatagramSocket result2 = this.subject.createDatagramSocket("test", 1);
        DatagramSocket result3 = this.subject.createDatagramSocket("test", socketAddress);
        DatagramSocket result4 = this.subject.createDatagramSocket("test", 1, localhost);
 

9
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: connect, setSoTimeout
public class RtpSocket { 
  private final byte [] buf = new byte[4096];
  private DatagramSocket socket;
 
  public RtpSocket(int localPort, InetSocketAddress remoteAddress) throws SocketException {
    socket = new DatagramSocket(localPort);
    socket.setSoTimeout(1);
    socket.connect(new InetSocketAddress(remoteAddress.getAddress().getHostAddress(), remoteAddress.getPort()));
    Log.d( "RtpSocket", "Connected to: " + remoteAddress.getAddress().getHostAddress() );
  } 
 
  public void setTimeout(int timeoutMillis) {
    try { 
      socket.setSoTimeout(timeoutMillis);
    } catch (SocketException e) {
      Log.w("RtpSocket", e);
    } 
  } 
 
  private long totalSendTime = 0;
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: close, isClosed
	// =========================================================== 
	// Methods 
	// =========================================================== 
 
	public static final void closeSocket(final DatagramSocket pDatagramSocket) {
		if(pDatagramSocket != null && !pDatagramSocket.isClosed()) {
			pDatagramSocket.close();
		} 
	} 
 
	public static final void closeSocket(final Socket pSocket) {
		if(pSocket != null && !pSocket.isClosed()) {
			try { 
				pSocket.close();
			} catch (final IOException e) {
				Debug.e(e);
			} 
		} 
	} 
 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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 */ 
					} 
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Java 8 DatagramSocket Questions & Answers:

See Code Examples for Java 8 DatagramSocket Methods: