Advertisement
heavenriver

ForeignAgent.java

Dec 11th, 2013
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. import java.io.*;
  2. import java.net.*;
  3. import java.util.*;
  4.  
  5. public class ForeignAgent
  6.     {
  7.     public static void main(String[] args) throws Exception
  8.         {
  9.         /* creates a socket with the local broadcast address, 192.168.1.255 */
  10.         DatagramSocket broadcastSocket = new DatagramSocket();
  11.         InetAddress broadcastIP = InetAddress.getByName("192.168.1.255");
  12.         InetAddress myIP = InetAddress.getByName("hostid");
  13.         byte[] data;
  14.         /* encapsulates a message in "data" containing myIP and a message that means the unit is available to serve as a foreign agent */
  15.         /* sends the message */
  16.         DatagramPacket packet = new DatagramPacket (data, data.length, broadcastIP, 8001);
  17.         broadcastSocket.send(packet);
  18.         /* performs other functions */
  19.        
  20.         broadcastSocket.close();
  21.         }
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement