The rbeacon module implements a peer-to-peer discovery service for local
networks.
Behaviours: gen_server.
A beacon can broadcast and/or capture service announcements using UDP messages on the local area network. This implementation uses IPv4 UDP broadcasts. You can define the format of your outgoing beacons, and set a filter that validates incoming beacons. Beacons are sent and received asynchronously in the background.
beacon() = pid()
beacon_opts() = [active | {active, true | false | once | integer()} | {interval, integer()} | noecho | {noecho, true | false}]
| broadcast_ip/1 | Return our own Broadcast IP address as printable string. |
| close/1 | close a beacon Close a beacon. |
| control/2 | Assigns a new controlling process Pid to beacon The controlling process is the process which receives messages from the beacon. |
| hostname/1 | Return our own IP address as printable string. |
| new/1 | Create a new beacon on a certain UDP port. |
| new/2 | Create a new beacon on a certain UDP port with options. |
| noecho/1 | Filter out any beacon that looks exactly like ours. |
| publish/2 | Start broadcasting beacon to peers at the specified interval. |
| recv/1 | wait to receive a beacon. |
| recv/2 | wait to receive a beacon with timeout. |
| set_interval/2 | Set broadcast interval in milliseconds (default is 1000 msec). |
| setopts/2 | set beacon options. |
| silence/1 | Stop broadcasting beacons. |
| subscribe/2 | Start listening to other peers; zero-sized filter means get everything All messages received by the peer will be then sent to the process owner. |
| unsubscribe/1 | Stop listening to other peers. |
broadcast_ip(Ref::beacon()) -> string()
Return our own Broadcast IP address as printable string
close(Ref::beacon()) -> ok
close a beacon Close a beacon.
control(Ref::beacon(), Pid::pid()) -> ok | {error, not_owner}
Assigns a new controlling process Pid to beacon
The controlling process is the process which receives messages from the
beacon. If called by any other process than the current controlling process,
{error, not_owner} is returned.
hostname(Ref::beacon()) -> string()
Return our own IP address as printable string
new(Port::integer()) -> {ok, beacon()} | {error, term()}
Create a new beacon on a certain UDP port.
new(Port::integer(), Options::beacon_opts()) -> {ok, beacon()} | {error, term()}
Create a new beacon on a certain UDP port with options.
noecho(Ref::beacon()) -> ok
Filter out any beacon that looks exactly like ours
publish(Ref::beacon(), Msg::binary()) -> ok | {error, term()}
Start broadcasting beacon to peers at the specified interval
recv(Ref::beacon()) -> {ok, Addr::string(), Msg::binary()} | {error, term()}
recv(Ref::beacon(), Timeout::integer() | infinity) -> {ok, Addr::string(), Msg::binary()} | {error, term()}
wait to receive a beacon with timeout. Timeout can be an integer in milliseconds or infinity.
set_interval(Ref::beacon(), Interval::integer()) -> ok | {error, term()}
Set broadcast interval in milliseconds (default is 1000 msec)
setopts(Ref::beacon(), Options::beacon_opts()) -> ok
set beacon options. Valid options are:
-
active,{active, true | false | once| N}: likeinet:setopts/1 -
{interval, N}: Set broadcast interval in milliseconds -
noecho | {noecho, true | false}: Filter out any beacon that looks exactly like ours.
silence(Ref::beacon()) -> ok
subscribe(Ref::beacon(), Filter::binary() | string()) -> ok
Start listening to other peers; zero-sized filter means get everything All messages received by the peer will be then sent to the process owner. Incoming messages are:
{rbeacon, Beacon, Message, SenderIp}: when a subscription is received{rbeacon, Beacon, closed}: when a beacon is closed{'EXIT', rbeacon, Beacon, Reason}: when a beacon exit anormaly
unsubscribe(Ref::beacon()) -> ok
Stop listening to other peers