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;
}
}
}
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);
}
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);
}
}
}
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);
}
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);
}
}
Aggregations