Hello everyone, I was trying to query local network of the PC I am trying to develop a sample, with Maven + Spring 3.2.5 and Vaadin Flow 24.3.12, with Java class where calling Network it should return local network like the ethernet with this code:
HI @ollit.1 , thank you for your answer… but probably I missed something and I’d need a clarification… creating a Java Vaadin PWA it is possible to encapsulate also a local server in a single jar/war to execute that Java code which would query local mobile phone’s network for example connected to a WiFi to get another custom device informations? Something that can do a native app usually…
All the application logic that you write with Flow in Java runs on the server which is typically a separate server rather than a JVM on the user’s PC.
It’s in theory possible to create a native app bundle that runs a Java server on the user’s PC and then shows the UI in the user’s regular browser or wrapped in e.g. an Electron shell. This is, however, outside of the officially supported way of using Vaadin so there won’t be any documentation or such to describe how it’s done.
One possibility for some cases could be that you integrate with various JavaScript APIs provided by the browser for interacting with external devices. But I’m not sure if the browser provides access to the things that you would need.
Hi, to only way to get this properly your way is using wasm.
It’s a challenge… because you will have to wrap entire springboot and vaadin in single file. (GrallVM for ex) It is how ever possible… but don’t count on in to work in production. In Other words there are more simple ways to do so.
HI @ecohen280 , thanks for your answer! Investigating some more about WASM you suggested, like here on this site : How to run Java in the browser with WebAssembly and remembering this page in Vaadin documentation , Deploying using Docker , looks like sort of with Docker that should be possible so once compiled it should become sort of like a native android app, but this time, executed in the browser so it can be executed also on iPhone mobiles for example, right?..
I think the most fundamental question here is why you would need the details of the local network in the first place? What problem you are trying to solve with that?
And based on answer to that question, could you image totally different kind of approaches to achieve the solution.
Hello Tatu Lund , thanks for your answer! I am trying to reach local network because I am planning to convert a native android app to pwa which queries custom devices connected to a Wifi network or their own hotspot to get information such as remaining battery life… so actually looking at local network which would be for example mobile wifi to obtain the mask for example 192.168.7.X and then polling from 1 to 255 sending socket query to the device fi exists there…
Actually looking around about those WASM who elad suggested earlier, seems there is a cheerpj which should work with networking as they say on their site…
WASM in itself will not help you since that would still run within the security sandbox of the user’s web browser that has the same limitations as anything run as JavaScript in the browser. A raw-sockets browser API was discussed a while ago but it was not adopted and implemented by browsers. This means that the network access has to be managed through code that runs outside of the browser, i.e. as a native application or in a regular JVM.
Cheerpj’s networking support doesn’t mean you can access arbitrary networking devices from the computer that runs the browser, it means you can use http/s and websockets: Networking - CheerpJ Documentation
you mean also in native android app? If yes, indeed I already made an android native java app which retrieves local mobile/tablet IP and from this, it queries all IPs between .1 and .255 with success… just I was thinking the possibility to convert as PWA so in the way instead to have native app only for android , a PWA would be executed also on iOS which its core is always sort-of linux as like as android…
indeed I already made an android native java app which retrieves local mobile/tablet IP and from this, it queries all IPs between .1 and .255 with success…
This is called ARP (Address Resolution Protocol).
In Android you can ask for permission to access Network
on as you already know
network data is located at
/proc/net/arp
A website and PWA does not have access for this (and they really should not)
as per IOS - only rooted devices might work?.
And in order to help you out , since it’s still Vaadin Forum :)
As I said in my start post in pure Java which is Vaadin, or Android too, I use NetworkInterface.getNetworkInterfaces() which is an internal java.net.* library function and it should normally return my local network.
Just at this point I suspect maybe if I compile and create a jar file then it would be like an encapsulated system…that’s why, as I said in my start post, I obtain a result yes, which is not the local network but a Wan Miniport (PPTP), and doing ipconfig/ifconfig it doesn’t show in the system list but it could be something like a “virtual network” inside the jar maybe… that’s why I was asking for…
Even I have to say, once running it as Application on Eclipse, I got the LAN Ethernet Adapter local network too, but just I don’t remember what I did exactly to retrieve that local network of my PC…