Search in sources :

Example 76 with DatagramPacket

use of java.net.DatagramPacket in project RPlay by bencall.

the class UDPListener method run.

public void run() {
    boolean fin = stopThread;
    while (!fin) {
        byte[] buffer = new byte[MAX_PACKET];
        DatagramPacket p = new DatagramPacket(buffer, buffer.length);
        try {
            synchronized (socket) {
                if (socket != null) {
                    socket.receive(p);
                    delegate.packetReceived(socket, p);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        // Stop
        synchronized (this) {
            fin = this.stopThread;
        }
    }
}
Also used : DatagramPacket(java.net.DatagramPacket) IOException(java.io.IOException)

Example 77 with DatagramPacket

use of java.net.DatagramPacket in project hazelcast by hazelcast.

the class MulticastDiscoverySender method initDatagramPacket.

private void initDatagramPacket() throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutput out;
    out = new ObjectOutputStream(bos);
    out.writeObject(multicastMemberInfo);
    byte[] yourBytes = bos.toByteArray();
    datagramPacket = new DatagramPacket(yourBytes, yourBytes.length, InetAddress.getByName(group), port);
}
Also used : ObjectOutput(java.io.ObjectOutput) DatagramPacket(java.net.DatagramPacket) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream)

Example 78 with DatagramPacket

use of java.net.DatagramPacket in project JAirPort by froks.

the class RaopServer method run.

@Override
public void run() {
    byte[] b = new byte[2048];
    DatagramPacket packet = new DatagramPacket(b, b.length);
    while (!Thread.interrupted()) {
        try {
            receiveSocket.receive(packet);
        } catch (IOException e) {
            e.printStackTrace();
            this.interrupt();
            continue;
        }
        if (clientSocketAddress == null) {
            clientSocketAddress = packet.getSocketAddress();
        }
        int offset = packet.getOffset();
        int length = packet.getLength();
        byte[] data = packet.getData();
        byte type = (byte) (data[offset + 1] & ~0x80);
        if (type == 0x60 || type == 0x56) {
            // audio data / resend
            if (type == 0x56) {
                offset = offset + 4;
                length = length - 4;
            }
            int seqno = (data[offset + 2] << 8) | data[offset + 3];
            putDataInBuffer(seqno, data, offset + 12, length - 12);
        }
    }
}
Also used : DatagramPacket(java.net.DatagramPacket) IOException(java.io.IOException)

Example 79 with DatagramPacket

use of java.net.DatagramPacket in project JAirPort by froks.

the class RaopServer method requestRtpResend.

public void requestRtpResend(int first, int last) throws IOException {
    if (first > last) {
        System.out.println(first + " > " + last);
        return;
    }
    int len = last - first + 1;
    byte[] b = new byte[] { (byte) 0x80, (byte) (0x55 | 0x80), 0x01, 0x00, (byte) ((first & 0xFF00) >> 8), (byte) (first & 0xFF), (byte) ((len & 0xFF00) >> 8), (byte) (len & 0xFF) };
    DatagramPacket packet = new DatagramPacket(b, 0, b.length, clientSocketAddress);
    receiveSocket.send(packet);
}
Also used : DatagramPacket(java.net.DatagramPacket)

Example 80 with DatagramPacket

use of java.net.DatagramPacket in project physical-web by google.

the class Ssdp method search.

public synchronized void search(SsdpMessage msg) throws IOException {
    if (mDatagramSocket != null) {
        byte[] bytes = msg.toString().getBytes(StandardCharsets.UTF_8);
        DatagramPacket dp = new DatagramPacket(bytes, bytes.length, mMulticastGroup);
        mDatagramSocket.send(dp);
    }
}
Also used : DatagramPacket(java.net.DatagramPacket)

Aggregations

DatagramPacket (java.net.DatagramPacket)302 IOException (java.io.IOException)126 DatagramSocket (java.net.DatagramSocket)121 InetAddress (java.net.InetAddress)69 SocketException (java.net.SocketException)43 Test (org.junit.Test)35 InetSocketAddress (java.net.InetSocketAddress)34 SocketTimeoutException (java.net.SocketTimeoutException)30 UnknownHostException (java.net.UnknownHostException)21 MulticastSocket (java.net.MulticastSocket)18 InterruptedIOException (java.io.InterruptedIOException)17 SocketAddress (java.net.SocketAddress)15 ByteBuffer (java.nio.ByteBuffer)11 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)11 SyslogConnection (org.opennms.netmgt.syslogd.api.SyslogConnection)11 PortUnreachableException (java.net.PortUnreachableException)9 ArrayList (java.util.ArrayList)9 SyslogMessageLogDTO (org.opennms.netmgt.syslogd.api.SyslogMessageLogDTO)8 BindException (java.net.BindException)7 Transactional (org.springframework.transaction.annotation.Transactional)7