Android Question Search network for websocket listener?

techknight

Well-Known Member
Licensed User
Longtime User
I have a websocket server in B4J that a B4A app connects to and is controlled by the B4J server.

Problem is, I cant always guarentee that I know the IP address of what B4J is sitting on.

This is all local LAN stuff, not over the internet. So is there a way to "search" the network for the websocket and connect to it when found?

Just curious.
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
I have a websocket server in B4J that a B4A app connects to and is controlled by the B4J server.

Problem is, I cant always guarentee that I know the IP address of what B4J is sitting on.

This is all local LAN stuff, not over the internet. So is there a way to "search" the network for the websocket and connect to it when found?

Just curious.
I don't know if this will work for you or not, but...

I have a B4A app (game) that has multiplayer over a local network. To save players having to enter the IP addresses of the other devices playing, I do a UDP broadcast over the network (usually on the .255 address, but there is a tutorial somewhere on the forum on finding the broadcast address), then when the devices find each other, I establish a TCP socket connection (with one device being the server & the others all being clients).

- Colin.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
A simpler alternative: assign the "server" a fixed IP on your LAN
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
its part of DHCP settings in router
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
A simpler alternative: assign the "server" a fixed IP on your LAN

If it were that simple. Problem is, I dont have access to everybody's LAN and their configuration for deployment. This is why I was asking about scanning the network. Here at my work I can control all of that.

Elsewhere, especially to the target market, there are several layers of bureaucracy before that could happen.
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
so you start your server in a guest network, true?
i think what you are looking for is a Broadcast / Multicast message.
if a app send a hello i am here in network every other app can fetch this message and send answer.

if you just have a notebook with your server app in guest network instead of ip a hostname should work.
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
Well the server app will be running on a PC inside of a Rack enclosure with multiple clients that need to know where this server is. But yes it appears a broadcast message will have to do. I have used them in the past but I didnt know if there was some other built in function.

The network configuration of the facility who has the server will vary of course. But it is a LAN only server that doesn't need the internet for anything other than maybe cloud file transfer. The server is just a Management Engine for all the clients locally.
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
i would try the pc name instead of the ip (if possible) and that pc name + port is part of the config in b4a client app.
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
But then you would need a nameserver, and then the nameserver has to be configured to resolve that. Right?
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
at home i think it handle dhcp in router, if a pc request a ip this device memory also the name.
in a company with windows enviroment i think its a Domain Controller server computer that can resolve hostnames into ip.
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
at home i think it handle dhcp in router, if a pc request a ip this device memory also the name.
in a company with windows enviroment i think its a Domain Controller server computer that can resolve hostnames into ip.

Yes but again, I cant rely on that as our system is a closed system. Its not meant to communicate with any device on the existing network except for what we have deployed that comes with our system, including android Apps.

It might be easier if I include my own wifi router with the system, and our system just be on its own subnet outside of the existing LAN, with accessing the outside LAN as WAN only. But then the End-users would have to switch WiFis. So eh... Maybe I will try the UDP route.
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
if all your devices are in the same network the only barrier/problem with UDP broadcast will be a firewall rule from admin.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
if all your devices are in the same network the only barrier/problem with UDP broadcast will be a firewall rule from admin.
That's true - some LANs have UDP broadcast disabled. If that's the case then there are a couple of possible fallbacks:

1) The client app has to have the server IP address entered manually (this could be a problem if the users don't know the server IP); or
2) The client app tries every IP address on the LAN until it finds the server. I've never tried this, but in theory it should work if the server is listening & you have some kind of "handshake" to establish that the client & server are supposed to be talking to each other.

- Colin.
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
2) The client app tries every IP address on the LAN until it finds the server.
with a Subnetzmask 255.255.255.0 there are 254 Hosts, u need try connect to all :)
with a Subnetzmask 255.255.0.0 there are 65.534 Hosts, it will take longer
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
with a Subnetzmask 255.255.255.0 there are 254 Hosts, u need try connect to all :)
with a Subnetzmask 255.255.0.0 there are 65.534 Hosts, it will take longer
I didn't say it was practical - just that in theory it should work! :)

- Colin.
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
I didn't say it was practical - just that in theory it should work! :)
- Colin.

sure, i know :)

i have a new idea,
if the server would register online as "copy protection" your
client apps can also connect online to register server and get the ip there.
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
Assuming the server is connected to the internet, then yes that could be a possibility.

Anyways, the target market/location of my setup are basically Schools, and Universities and of course other sports venues.

Most schools and universities have restricted internet so the IT guys would have to enter the MAC address as an allow for certain access levels. Unfortunately in that environment alot of that has to go through many layers of bureaucracy.

I am thinking at this point is maybe keeping my system completely isolated, on its own subnet, only using the venue's network as WAN internet access.

so that means all devices requiring the use of the system needs to be on its network, like WiFi, etc. Unless I decide to forward some ports over. But then again you would need the WAN IP that would get assigned from the School's network. But the IT guy would have that anyways. :)
 
Upvote 0
Top