Issue
I am building an attendance application for my college, where in I want to mark student attendance through the network. Every class room has seperate router and I want to basically check if student are sitting in the router's range and mark their attendance accordingly. How can I check if there are sitting in router's range, is this possible through web socket? or How can I ping or do something through web sockets to check if particular ip is alive or not?
I am using kotlin to develop my application. Please help.
Solution
How can I ping or do something through web sockets to check if particular ip is alive or not?
You cant force a client to allow you to ping them just using their ip address. The best way to go is to connect your users to a central server (through a websocket in your example) and check heartbeats on the websocket.
For this, of-course you have to first authorize your students and make sure everyone has a token on their websocket so that you can track their existence in your system. Then you need some kind of heartbeat system. Most websocket implementations I have seen, have already implemented ping
and pong
. It can work both ways:
One point, to check if other point is connected should send ping
requests and the other point automatically sends back a pong
message if they are connected.
In an app we wrote, we have an interval to send pings to clients, and we persist their pong timestamp. If last pong timestamp is too old, then we know that connection is failed or client is not available on the network.
Although, if websocket closes or faces an error, a method (like onError()
and onClose()
) gets called and you are informed. But implementing an heartbeat service can help you make sure your connection is actually alive and is a MUST in your websocket based system.
How can I check if there are sitting in router's range, is this possible through web socket?
If Im not wrong, you are in charge of designing both sides of your application (client and server). So, you can make users try to connect to your LOCAL ip address again and again until the connection is successful. You just have to make sure your server ip address is reachable through those other routers.
NOTE: on the local network, if students should not be able to connect using another classroom router, then you can check their websocket ip address. Before that there should be an table to map each user to the ip address they can send message from.
Another way to achieve this IF YOUR SERVER IS NOT IN THAT LOCAL NETWORK is to give those routes same public ip address (or static ip addresses), and route your traffic through internet to your server public ip address. Then to make sure users can only connect from those routers (within range of those routers), you have to allow those routers IP address in your server firewall (or you can do it in the server application side) and block any other connections on your websocket port.
NOTE 2 again, if your server is not in your local network, but you still want to make sure each user is in its valid classroom, you need a proxy server. works like this:
Client connects to its classroom router > router connects to local proxy server > proxy server adds router ip address to websocket message and sends it to public server > public server can process message and has user local ip address
Answered By - Sep GH
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.