Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.*;
- import java.util.*;
- import java.io.IOException;
- //package test;
- class Main {
- // static String hostname = new String("bigoli.salatschuessel.net");
- static String hostname = new String("10.0.0.23");
- private final static String IPV4_UPNP_HOST = "239.255.255.250";
- private static InetAddress getUPNPAddress() throws IOException {
- return InetAddress.getByAddress(IPV4_UPNP_HOST, new byte[]{(byte) 239, (byte) 255, (byte) 255, (byte) 250});
- }
- public static void main(String args[]) throws SocketException, UnknownHostException, IOException{
- NetworkInterface ni = NetworkInterface.getByInetAddress(InetAddress.getByName(hostname));
- System.out.println(ni);
- MulticastSocket ssdpSocket = new MulticastSocket();
- if (ni != null) {
- ssdpSocket.setNetworkInterface(ni);
- // force IPv4 address
- Enumeration<InetAddress> enm = ni.getInetAddresses();
- while (enm.hasMoreElements()) {
- InetAddress ia = enm.nextElement();
- if (!(ia instanceof Inet6Address)) {
- ssdpSocket.setInterface(ia);
- break;
- }
- }
- }
- System.out.println("Sending message from multicast socket on network interface: " + ssdpSocket.getNetworkInterface());
- System.out.println("Multicast socket is on interface: " + ssdpSocket.getInterface());
- ssdpSocket.setTimeToLive(32);
- ssdpSocket.joinGroup(getUPNPAddress());
- System.out.println("Socket Timeout: " + ssdpSocket.getSoTimeout());
- System.out.println("Socket TTL: " + ssdpSocket.getTimeToLive());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement