use of java.net.DatagramSocket in project jcollectd by collectd.
the class ReceiverTest method testBound.
public void testBound() throws Exception {
DatagramSocket socket = getReceiver().getSocket();
assertTrue(socket.isBound());
getLog().info("Bound to LocalPort=" + socket.getLocalPort() + ", LocalAddress=" + socket.getLocalAddress().getHostAddress());
}
use of java.net.DatagramSocket in project jcollectd by collectd.
the class ReceiverTest method createSocket.
protected DatagramSocket createSocket() throws IOException {
DatagramSocket socket = new DatagramSocket();
_receiver.setListenAddress("127.0.0.1");
return socket;
}
use of java.net.DatagramSocket in project jcollectd by collectd.
the class ReceiverTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
_receiver = new UdpReceiver();
DatagramSocket socket = createSocket();
_receiver.setSocket(socket);
_receiverThread = new ReceiverThread();
_receiverThread.start();
}
use of java.net.DatagramSocket in project Smack by igniterealtime.
the class JingleManagerTest method testRTPBridge.
/**
* RTP Bridge Test
*/
public void testRTPBridge() {
resetCounter();
try {
ProviderManager.getInstance().addIQProvider(RTPBridge.NAME, RTPBridge.NAMESPACE, new RTPBridge.Provider());
RTPBridge response = RTPBridge.getRTPBridge(getConnection(0), "102");
class Listener implements Runnable {
private byte[] buf = new byte[5000];
private DatagramSocket dataSocket;
private DatagramPacket packet;
public Listener(DatagramSocket dataSocket) {
this.dataSocket = dataSocket;
}
public void run() {
try {
while (true) {
// Block until a datagram appears:
packet = new DatagramPacket(buf, buf.length);
dataSocket.receive(packet);
incCounter();
}
} catch (Exception e) {
LOGGER.log(Level.WARNING, "exception", e);
}
}
}
try {
byte[] packet = { 0, 0, 1, 1, 1, 1, 1 };
DatagramSocket ds0 = new DatagramSocket(14004, InetAddress.getByName("0.0.0.0"));
DatagramSocket ds1 = new DatagramSocket(14050, InetAddress.getByName("0.0.0.0"));
DatagramPacket echo0 = new DatagramPacket(packet, packet.length, InetAddress.getLocalHost(), response.getPortA());
DatagramPacket echo1 = new DatagramPacket(packet, packet.length, InetAddress.getLocalHost(), response.getPortB());
ds1.send(echo1);
ds0.send(echo0);
Thread.sleep(500);
Thread t0 = new Thread(new Listener(ds0));
Thread t1 = new Thread(new Listener(ds1));
t0.start();
t1.start();
int repeat = 300;
for (int i = 0; i < repeat; i++) {
ds0.send(echo0);
ds1.send(echo1);
Thread.sleep(200);
}
System.out.println(valCounter());
assertTrue(valCounter() == repeat * 2 + 1);
t0.stop();
t1.stop();
ds0.close();
ds1.close();
} catch (Exception e) {
LOGGER.log(Level.WARNING, "exception", e);
}
} catch (Exception e) {
LOGGER.log(Level.WARNING, "exception", e);
}
}
use of java.net.DatagramSocket in project Smack by igniterealtime.
the class AudioMediaSession method createSession.
/**
* Create a Session using Speex Codec.
*
* @param localhost localHost
* @param localPort localPort
* @param remoteHost remoteHost
* @param remotePort remotePort
* @param eventHandler eventHandler
* @param quality quality
* @param secure secure
* @param micOn micOn
* @return MediaSession
* @throws NoProcessorException
* @throws UnsupportedFormatException
* @throws IOException
* @throws GeneralSecurityException
*/
public static MediaSession createSession(String localhost, int localPort, String remoteHost, int remotePort, MediaSessionListener eventHandler, int quality, boolean secure, boolean micOn) throws NoProcessorException, UnsupportedFormatException, IOException, GeneralSecurityException {
SpeexFormat.setFramesPerPacket(1);
/**
* The master key. Hardcoded for now.
*/
byte[] masterKey = new byte[] { (byte) 0xE1, (byte) 0xF9, 0x7A, 0x0D, 0x3E, 0x01, (byte) 0x8B, (byte) 0xE0, (byte) 0xD6, 0x4F, (byte) 0xA3, 0x2C, 0x06, (byte) 0xDE, 0x41, 0x39 };
/**
* The master salt. Hardcoded for now.
*/
byte[] masterSalt = new byte[] { 0x0E, (byte) 0xC6, 0x75, (byte) 0xAD, 0x49, (byte) 0x8A, (byte) 0xFE, (byte) 0xEB, (byte) 0xB6, (byte) 0x96, 0x0B, 0x3A, (byte) 0xAB, (byte) 0xE6 };
DatagramSocket[] localPorts = MediaSession.getLocalPorts(InetAddress.getByName(localhost), localPort);
MediaSession session = MediaSession.createInstance(remoteHost, remotePort, localPorts, quality, secure, masterKey, masterSalt);
session.setListener(eventHandler);
session.setSourceDescription(new SourceDescription[] { new SourceDescription(SourceDescription.SOURCE_DESC_NAME, "Superman", 1, false), new SourceDescription(SourceDescription.SOURCE_DESC_EMAIL, "cdcie.tester@je.jfcom.mil", 1, false), new SourceDescription(SourceDescription.SOURCE_DESC_LOC, InetAddress.getByName(localhost) + " Port " + session.getLocalDataPort(), 1, false), new SourceDescription(SourceDescription.SOURCE_DESC_TOOL, "JFCOM CDCIE Audio Chat", 1, false) });
return session;
}
Aggregations