Package dijjer.io.comm

Examples of dijjer.io.comm.UdpSocketManager


        final Peer source = new Peer(Inet4Address.getLocalHost(), (short) 5555);
        final Peer dest = new Peer(Inet4Address.getLocalHost(), (short) 5556);
        final MessageType ping = DMT.ping;
        final MessageType pong = DMT.pong;
        final UdpSocketManager sourceUSM = new UdpSocketManager((short) 5555);
        final UdpSocketManager destUSM = new UdpSocketManager((short) 5556);
        ping.addField("id", Integer.class);
        pong.addField("id", Integer.class);
        // Sender
        Misc.startThread(new Runnable() {
            public void run() {
                int id = 0;
                for(int i=0;i<15;i++) {
                    Message p = new Message(ping);
                    p.set("id", id++);
                    p.set(DMT.EXTERNAL_ADDRESS, dest);
                    System.out.print("Sender: Ping sent... ");
                    sourceUSM.send(dest, p);
                    Message r = sourceUSM.waitFor(MessageFilter.create(10000, pong).setField("id",
                        new Integer(id - 1)));
                    if (r != null) {
                        _pongcount++;
                        synchronized (lock) {
                            lock.notifyAll();
                        }
                        System.out.println("Sender: Pong received.");
                    } else {
                        System.out.println("Timed out");
                    }
                }
            }
        });
        // Receiver
        for (int i = 0; i < 15; i++) {
            Message p = destUSM.waitFor(MessageFilter.create(10000, ping));
            if (p != null) {
                _pingcount++;
                System.err.println("Receiver: Ping " + p.getInt("id") + " received.  Sending pong");
                Message po = new Message(pong);
                po.set("id", p.getInt("id"));
                po.set(DMT.EXTERNAL_ADDRESS, source);
                destUSM.send(source, po);
            }
        }
        assertEquals(15, _pingcount);
        synchronized(lock) {
            lock.wait(2000);
View Full Code Here


* Comments
*/
public class BlockTransferTest extends TestCase {

  public void testTransfer() throws Exception {
    UdpSocketManager usm1 = new UdpSocketManager(8000);
    UdpSocketManager usm2 = new UdpSocketManager(8001);
    UdpSocketManager usm3 = new UdpSocketManager(8002);
    usm1.setDropProbability(8);
    usm2.setDropProbability(8);
    usm3.setDropProbability(8);
    Peer p1 = new Peer(InetAddress.getLocalHost(), 8000);
    Peer p2 = new Peer(InetAddress.getLocalHost(), 8001);
    Peer p3 = new Peer(InetAddress.getLocalHost(), 8002);
    byte[] block = new byte[1024 * 256];
    for (int x = 0; x < block.length; x++) {
View Full Code Here

TOP

Related Classes of dijjer.io.comm.UdpSocketManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.