Hi,
I am looking to access UDP data from multicast address 224.0.0.251 port 5353 , jNetwork does not allow the entry of this IP.
From my previous post , it has been suggested to use Java with Javaobject.
Is this possible ? does anyone have any examples ?
I found this on Stackoverflow but do not how to format it to use in B4J , or that is actually works
Thank you
I have looked at other ways to get the information I am looking for.
1 is to monitor port 67
This almost works perfectly.
The computer runs its own DHCP server allocating an initial IP address using 192.168.11.??? subnet
Now I can check which endpoints are alive without having to ping each IP address.
Once they are found , I need to REALLOCATE new IPs on a different Subnet using the same adapter. Which works well
but I cannot change the monitoring subnet to 192.168.10.???
restarted the program and it still only monitors 192.168.11.255, I want it to monitor 192.168.10.255 so I can receive the new data for port 68
This is the setup of the Ethernet Adapter so I can use it for both subnets
I am looking to access UDP data from multicast address 224.0.0.251 port 5353 , jNetwork does not allow the entry of this IP.
From my previous post , it has been suggested to use Java with Javaobject.
Is this possible ? does anyone have any examples ?
I found this on Stackoverflow but do not how to format it to use in B4J , or that is actually works
Thank you
B4X:
import java.net.MulticastSocket;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
public class Main {
public static void main(String[] args) {
if( args.length == 0 ) runClient();
if(args[0].equals("s")) runServer();
else runClient();
}
static String mcastAddr = "239.255.100.100"; // Chosen at random from local network block at http://www.iana.org/assignments/multicast-addresses/multicast-addresses.xhtml
static int port = 4446;
public static void runServer() {
while (true) {
try {
MulticastSocket s = new MulticastSocket(port);
InetAddress group = InetAddress.getByName(mcastAddr);
s.joinGroup(group);
byte[] recData = new byte[100];
DatagramPacket receivePacket = new DatagramPacket(recData, recData.length);
s.receive(receivePacket);
String strrec = new String(recData,0,receivePacket.getLength());
print("server received: " + strrec);
print("from: " + receivePacket.getAddress().toString());
if(strrec.equals("Are you there?")) {
String msg = "Here I am";
byte[] msgData = msg.getBytes();
DatagramPacket msgPacket = new DatagramPacket(msgData, msgData.length, receivePacket.getAddress(), receivePacket.getPort());
s.send(msgPacket);
print("server sent: " + msg + "\n");
} else {
print("Didn't send; unrecognized message.");
}
} catch (Exception e) {
print(e.toString());
}
}
}
public static void runClient() {
try {
DatagramSocket s = new DatagramSocket();
String msg = "Are you there?"; // Magic string
byte[] msgData = msg.getBytes();
DatagramPacket datagramPacket = new DatagramPacket(msgData, msgData.length, InetAddress.getByName(mcastAddr), port);
s.send(datagramPacket);
print("client sent: " + msg);
byte[] recData = new byte[100];
DatagramPacket receivePacket = new DatagramPacket(recData, recData.length);
s.receive(receivePacket);
String strrec = new String(recData,0,receivePacket.getLength());
print("client received: " + strrec);
print("from " + receivePacket.getAddress().toString() + " : " + receivePacket.getPort());
System.exit(0);
} catch (Exception e) {
print(e.toString());
}
}
static void print(String s) { System.out.println(s); }
}
I have looked at other ways to get the information I am looking for.
1 is to monitor port 67
Message received: Length=308, Offset=0, Host=192.168.11.170, Port=68
This almost works perfectly.
The computer runs its own DHCP server allocating an initial IP address using 192.168.11.??? subnet
Now I can check which endpoints are alive without having to ping each IP address.
Once they are found , I need to REALLOCATE new IPs on a different Subnet using the same adapter. Which works well
but I cannot change the monitoring subnet to 192.168.10.???
restarted the program and it still only monitors 192.168.11.255, I want it to monitor 192.168.10.255 so I can receive the new data for port 68
This is the setup of the Ethernet Adapter so I can use it for both subnets
Last edited: