Package peer

Examples of peer.Peer


     
      //Get required info
//      String myAddress = InetAddress.getLocalHost().getHostAddress();
     
      //new peer broadcast
      Peer pulsePeer = new Peer(myAddress,latency,LocalFileOperation.getFileCount());
      MessageConvertor messageConvert = new MessageConvertor();
      byte[] peerAsByteArray = messageConvert.serializePeerPing(pulsePeer);
      pulseConsole.log("Thread: " + this.getName() + " - Converted Peer ID Message");           
     
     
     
      //old stuff below
      multiSocket.joinGroup(group);
      pulseConsole.log("Thread: " + this.getName() + " - Getting datagram packet");
      DatagramPacket hi = new DatagramPacket(peerAsByteArray,
          peerAsByteArray.length, group, broadcastSocket);
      int i = 0;
     
      pulseConsole.log("Thread: " + this.getName() + " - Pulse.ping()");
      while(!closeDown) {
       
        //Update Peer with latest Time
        pulsePeer.setLastRefresh(Calendar.getInstance().getTime());
       
        //Reserialise
        peerAsByteArray = messageConvert.serializePeerPing(pulsePeer);
       
        hi = new DatagramPacket(peerAsByteArray,
            peerAsByteArray.length, group, broadcastSocket);
       
//        Yield to other threads - make app more responsive
        Thread.yield();
       
        // Need to construct the Peer object everytime we go through the loop
        // or just get the dynamic data (latency, file list etc)
        sleep(1000 * PULSE_DELTA);
        multiSocket.send(hi);
        pulseConsole.log("Thread: " + this.getName() + " : Pinging: " + ++i +" Details - Latency: "+pulsePeer.getLatency()+" NumberOfFiles: "+pulsePeer.getNumberOfFiles());
      }
      multiSocket.leaveGroup(group);
      pulseConsole.log("Thread: " + this.getName() + " - Departed Multicast Socket Group");
    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here

TOP

Related Classes of peer.Peer

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.