Пример #1
0
 /** Broadcast the event to all connected parties. */
 public void sendEvent(NetworkEvent event) {
   if (!myReceivedMsgs.contains(event.getMsgId())) {
     // Only set the host id if we are initiating the event
     event.setHostId(myServerHash);
     myReceivedMsgs.add(event.getMsgId());
   }
   for (NetworkConnection conn : myConnections.values()) {
     try {
       System.out.println("Sending to " + conn + ": " + event);
       conn.write(event);
     } catch (IOException ioe) {
       System.out.println("Could not send event to " + conn);
     }
   }
 }
Пример #2
0
 /** Send the event to the host. If we don't know how to reach the host, returns false. */
 public boolean sendEvent(Long host, NetworkEvent event) {
   NetworkConnection conn = myConnections.get(host);
   try {
     if (conn != null) {
       if (!myReceivedMsgs.contains(event.getMsgId())) {
         // Only set the host id if we are initiating the event
         event.setHostId(myServerHash);
         myReceivedMsgs.add(event.getMsgId());
       }
       System.out.println("Sending to " + conn + ": " + event);
       conn.write(event);
       return true;
     } else {
       System.out.println("Unrecognized host: " + host);
     }
   } catch (IOException e) {
     System.out.println("Could not send event to " + conn);
   }
   return false;
 }