Package java.net

Examples of java.net.DatagramSocket$Lock


    private DatagramSocket getDatagramSocket() {

        try {

            return new DatagramSocket();

        } catch (SocketException ex) {

            throw new RuntimeException(ex);
        }
View Full Code Here


    public void start() {
        this.serverThread.start();
    }

    public static TestServer build() throws SocketException {
        return new TestServer(new ServerThread(new DatagramSocket(12201)));
    }
View Full Code Here

        if( so.getProtocol().equals( OSCChannel.TCP )) {
          final ServerSocket ss = new ServerSocket( 0 );
          serverPort = ss.getLocalPort();
          ss.close();
        } else if( so.getProtocol().equals( OSCChannel.UDP )) {
          final DatagramSocket ds = new DatagramSocket();
          serverPort = ds.getLocalPort();
          ds.close();
        } else {
          throw new IllegalArgumentException( "Illegal protocol : " + so.getProtocol() );
        }
      }
   
View Full Code Here

      public void openBroadcaster() throws Exception
      {
         if (localBindPort != -1)
         {
            broadcastingSocket = new DatagramSocket(localBindPort, localAddress);
         }
         else
         {
            if (localAddress != null)
            {
               HornetQClientLogger.LOGGER.broadcastGroupBindError();
            }
            broadcastingSocket = new DatagramSocket();
         }

         open = true;
      }
View Full Code Here

   * @param host Hostname or IP adress
   * @param port number
   * @throws SocketException if Socket can't be opened
   */
  public Client(String host, int port) throws SocketException {
    this.socket = new DatagramSocket(port);
    this.server = new InetSocketAddress(host, 1234);
  }
View Full Code Here

  }
 
  public void startServer() {
    try {
      ExecutorService exec = Executors.newFixedThreadPool(100);
      this.socket = new DatagramSocket(SERVER_PORT);
      while (true) {
        byte[] buf = new byte[256];
        DatagramPacket dp = new DatagramPacket(buf, buf.length);
        this.socket.receive(dp);
        //FIXME feature : add a queue.
View Full Code Here

    static int senseMaxFragSize() {
        int upper=4096;
        int lower=0;
        int highest_failed=-1;
        DatagramSocket sock;
        byte[] buf;
        DatagramPacket packet;
        InetAddress local_addr;
        final int num_iterations=15;

        try {
            sock=new DatagramSocket();
            local_addr=InetAddress.getLocalHost();
        }
        catch(Exception ex) {
            System.err.println("failed creating DatagramSocket: " + ex);
            return lower;
        }

        for(int i=0; i < num_iterations && lower < upper; i++) { // iterations to approximate frag_size
            try {
                buf=new byte[upper];
                // System.out.println("** upper=" + upper + " (lower=" + lower + ")");
                packet=new DatagramPacket(buf, buf.length, local_addr, 9);
                sock.send(packet);
                lower=Math.max(lower, upper);
                System.out.println("-- trying " + lower + " [OK]");
                upper=upper * 2;
                if(highest_failed > -1)
                    upper=Math.min(highest_failed, upper);
View Full Code Here

        return lower;
    }


    public static void main(String[] args) {
        DatagramSocket sock;
        DatagramPacket packet;
        int size=0, frag_size=0;
        byte[] buf;

        try {
            size=senseMaxFragSize();
            System.out.println("-- fine tuning (starting at " + size + "):");
            sock=new DatagramSocket();
            for(; ;) {
                buf=new byte[size];
                packet=new DatagramPacket(buf, buf.length, InetAddress.getLocalHost(), 9);
                sock.send(packet);
                // System.out.print(size + " ");
                // System.out.println(size + " [OK]");
                frag_size=size;
                size++;
            }
View Full Code Here

    static long start, stop;
    private static final String LOOPBACK="LOOPBACK(down_thread=false;up_thread=false)";


    public static void main(String[] args) {
        DatagramSocket sock=null;
        Receiver receiver;
        int num_msgs=1000, num_sent=0, group_port=7500, num_yields=0;
        DatagramPacket packet;
        InetAddress group_addr=null;
        int[][] matrix;
        boolean jg=false; // use JGroups channel instead of UDP MulticastSocket
        JChannel channel=null;
        String group_name="SpeedTest-Group";
        Message send_msg;
        boolean debug=false, cummulative=false, busy_sleep=false, yield=false, loopback=false;
        Debugger debugger=null;
        long sleep_time=1; // sleep in msecs between msg sends
        ExposedByteArrayOutputStream output=new ExposedByteArrayOutputStream(64);
        String props;


        props="UDP(mcast_addr=224.0.0.36;mcast_port=55566;ip_ttl=32;" +
                "ucast_send_buf_size=32000;ucast_recv_buf_size=64000;" +
                "mcast_send_buf_size=32000;mcast_recv_buf_size=64000):" +
                "PING(timeout=2000;num_initial_members=3):" +
                "MERGE2(min_interval=5000;max_interval=10000):" +
                "FD_SOCK:" +
                "VERIFY_SUSPECT(timeout=1500):" +
                "pbcast.NAKACK(max_xmit_size=8192;gc_lag=50;retransmit_timeout=600,800,1200,2400,4800):" +
                "UNICAST(timeout=1200):" +
                "pbcast.STABLE(desired_avg_gossip=10000):" +
                "FRAG(frag_size=8192;down_thread=false;up_thread=false):" +
                "pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;" +
                "shun=false;print_local_addr=true):" +
                "pbcast.STATE_TRANSFER";
                //  "PERF(details=true)";



        for(int i=0; i < args.length; i++) {
            if("-help".equals(args[i])) {
                help();
                return;
            }
            if("-jg".equals(args[i])) {
                jg=true;
                continue;
            }
            if("-loopback".equals(args[i])) {
                loopback=true;
                continue;
            }
            if("-props".equals(args[i])) {
                props=args[++i];
                continue;
            }
            if("-debug".equals(args[i])) {
                debug=true;
                continue;
            }
            if("-cummulative".equals(args[i])) {
                cummulative=true;
                continue;
            }
            if("-busy_sleep".equals(args[i])) {
                busy_sleep=true;
                continue;
            }
            if("-yield".equals(args[i])) {
                yield=true;
                num_yields++;
                continue;
            }
            if("-sleep".equals(args[i])) {
                sleep_time=Long.parseLong(args[++i]);
                continue;
            }
            if("-num_msgs".equals(args[i])) {
                num_msgs=Integer.parseInt(args[++i]);
                continue;
            }
            help();
            return;
        }

        System.out.println("jg       = " + jg +
                "\nloopback = " + loopback +
                "\ndebug    = " + debug +
                "\nsleep    = " + sleep_time +
                "\nbusy_sleep=" + busy_sleep +
                "\nyield=" + yield +
                "\nnum_yields=" + num_yields +
                "\nnum_msgs = " + num_msgs +
                           '\n');



        try {
            matrix=new int[num_msgs][2];
            for(int i=0; i < num_msgs; i++) {
                for(int j=0; j < matrix[i].length; j++)
                    matrix[i][j]=0;
            }

            if(jg) {
                if(loopback) {
                    ProtocolStackConfigurator conf=ConfiguratorFactory.getStackConfigurator(props);
                    String tmp=conf.getProtocolStackString();
                    int index=tmp.indexOf(':');
                    props=LOOPBACK + tmp.substring(index);
                }
                channel=new JChannel(props);
                // System.out.println("props:\n" + channel.getProperties());
                channel.connect(group_name);
                if(debug) {
                    debugger=new Debugger(channel, cummulative);
                    debugger.start();
                }
            }
            else {
                group_addr=InetAddress.getByName("224.0.0.36");
                sock=new DatagramSocket();
            }

            if(debug) {
                System.out.println("Press key to start");
                System.in.read();
            }
            receiver=new Receiver(group_addr, group_port, channel, matrix, jg);
            receiver.start();

            byte[] buf;
            DataOutputStream out;

            start=System.currentTimeMillis();
            for(int i=0; i < num_msgs; i++) {
                // buf=Util.objectToByteBuffer(new Integer(i));
                output.reset();
                out=new DataOutputStream(output);
                out.writeInt(i);
                out.flush();
                buf=output.getRawBuffer();
                out.close();

                if(jg) {
                    send_msg=new Message(null, null, buf, 0, buf.length);
                    channel.send(send_msg);
                }
                else {
                    packet=new DatagramPacket(buf, buf.length, group_addr, group_port);
                    sock.send(packet);
                }
                num_sent++;
                if(num_sent % 1000 == 0)
                    System.out.println("-- sent " + num_sent);
View Full Code Here

   @version $Revision: 1.5 $
*/
public class McastTest {

    public static void main(String args[]) { 
  DatagramSocket  sock;
  DatagramPacket  packet;
  byte[]          buf=new byte[0];
  boolean         receiver=true;
  String          val;
  InetAddress     addr=null;
  int             port=0;

 
  for(int i=0; i < args.length; i++) {
      val=args[i];
      if("-help".equals(val)) {
    help();
    return;
      }
      if("-sender".equals(val)) {
    receiver=false;
    continue;
      }
      if("-receiver".equals(val)) {
    receiver=true;
    try {
        addr=InetAddress.getByName(args[++i]);
        port=Integer.parseInt(args[++i]);
    }
    catch(Exception e) {
        System.err.println(e);
        help();
        return;
    }
    continue;
      }
      help();
  }


  try {
      if(receiver) {
    sock=new DatagramSocket(port, addr);
    System.out.println("Socket=" + sock.getLocalAddress() + ':' + sock.getLocalPort());
    System.out.println("starting as receiver");
    receiverLoop(sock);
      }
      else {
    sock=new DatagramSocket();
    System.out.println("Socket=" + sock.getLocalAddress() + ':' + sock.getLocalPort());
    System.out.println("starting as sender");
    senderLoop(sock);
      }
  }
  catch(Exception e) {
View Full Code Here

TOP

Related Classes of java.net.DatagramSocket$Lock

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.