I don't see any (easy) way to get around having to have your clients let the server know they want to receive data. I suppose you can have the clients just close the socket when they're tired of listening and the server could remove them when the send fails but you still need some way to know which clients to send to.
Since you're on a LAN, I suppose you could send to the broadcast address and let the clients listen when they want to. If you are dealing with a sane OS you might want to check out IO::Socket::Multicast.
| [reply] |
the server could remove them when the send fails
That won't work. The send won't fail if the receiver stops receiving. You need some explicit disconnection mechanism.
- send doesn't wait for the datagram to be sent and acknowledged, so at best you'd know if a past send failed.
- There's no connection to keep track of a past send failures.
- There's no acknowledgment sent by the remote end to say it didn't fail.
The send will only fail if there's a local error (e.g. bad argument, no more resources, etc)
Kudos for IO::Socket::Multicast, though
| [reply] [d/l] |
If this was my project, I would definitely use an explicit disconnection.
That said, ICMP does provide "Destination Unreachable" which could be used to detect clients that are MIA. Of course, using ICMP for this would be a lot of work for very little practical gain, which is why I recommended multicast.
| [reply] |
| [reply] |
However, would this mean that every client would have to send something to the server every time they want to receive something?
No, just once. Well, maybe once in a while. The server should forget connects that it has received a long time ago to avoid sending to a machine that didn't properly disconnect, but that's no longer interested.
| [reply] |