Sub Process_Globals
Private servSocket As ServerSocket
End Sub
Sub AppStart (Args() As String)
servSocket.Initialize(0, "servSocket")
Dim jo As JavaObject = Me
jo.RunMethod("PrintAllInterfaces", Null)
jo.RunMethod("InitServerSocket", Array(servSocket, "lo", 5000))
servSocket.Listen
End Sub
#if JAVA
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Enumeration;
import anywheresoftware.b4a.objects.SocketWrapper.ServerSocketWrapper;
public static void PrintAllInterfaces() throws Exception {
for (Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); e.hasMoreElements();) {
System.out.println(e.nextElement());
}
}
public static void InitServerSocket(ServerSocketWrapper ServerSocket, String interfaceName, int port) throws Exception {
NetworkInterface ni = NetworkInterface.getByName(interfaceName);
Enumeration e = ni.getInetAddresses();
InetAddress ia = (InetAddress) e.nextElement();
ServerSocket.ssocket = new ServerSocket(port, 0, ia);
}
#End If
Attachments