i’m teacher and use processing in teaching
i ve 2 networks cards in the computer of the student. so i have 2 ipadresse. (ethernet and wlan)
how to specify the second adresse ip in : s = new Server(this, 8080);
i can’t set for exemple s = new Server(this, 8080,“192.168.1.12”);
because it will only works on one computer. I want it will work on any computer of my classroom
i have to set in s = new Server(this, 8080); the second ip adresse for the app works
thanks a lot
ps : sorry for the writting, i’m french
thanks to chatgpt i have a solution to implement.
import java.net.*;
import java.util.*;
void setup() {
size(400, 200);
try {
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
NetworkInterface iface = interfaces.nextElement();
if (!iface.isLoopback() && iface.isUp()) {
Enumeration<InetAddress> addresses = iface.getInetAddresses();
while (addresses.hasMoreElements()) {
InetAddress addr = addresses.nextElement();
println("Interface: " + iface.getName() + ", IP: " + addr.getHostAddress());
}
}
}
}
catch (SocketException e) {
e.printStackTrace();
}
}
with addr.getHostAddress(), i have the IP of the computer
Hello @techno,
I took interest but could not run the code you provided because it was not properly formatted.
See:
https://discourse.processing.org/faq#format-your-code
I cut and past your code into ChatGPT and it corrected it.
Here is the code correctly formatted for posting:
void setup() {
size(400, 200);
try {
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
NetworkInterface iface = interfaces.nextElement();
if (!iface.isLoopback() && iface.isUp()) {
Enumeration<InetAddress> addresses = iface.getInetAddresses();
while (addresses.hasMoreElements()) {
InetAddress addr = addresses.nextElement();
println("Interface: " + iface.getName() + ", IP: " + addr.getHostAddress());
}
}
}
} catch (SocketException e) {
e.printStackTrace();
}
}
:)