Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.*;
- import java.util.*;
- public class ForeignAgent
- {
- public static void main(String[] args) throws Exception
- {
- /* creates a socket with the local broadcast address, 192.168.1.255 */
- DatagramSocket broadcastSocket = new DatagramSocket();
- InetAddress broadcastIP = InetAddress.getByName("192.168.1.255");
- InetAddress myIP = InetAddress.getByName("hostid");
- byte[] data;
- /* encapsulates a message in "data" containing myIP and a message that means the unit is available to serve as a foreign agent */
- /* sends the message */
- DatagramPacket packet = new DatagramPacket (data, data.length, broadcastIP, 8001);
- broadcastSocket.send(packet);
- /* performs other functions */
- broadcastSocket.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement