-
Notifications
You must be signed in to change notification settings - Fork 0
/
broadcast.erl
36 lines (34 loc) · 873 Bytes
/
broadcast.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
%%%-------------------------------------------------------------------
%%% @author ben
%%% @copyright (C) 2017, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 02. mar 2017 14:15
%%%-------------------------------------------------------------------
%% C:\Users\ben\Desktop\Erlang tcp_udp_http
%% cd("C:/Users/ben/Desktop/Erlang tcp_udp_http").
%%
-module(broadcast).
-author("ben").
%% API
-compile(export_all).
send(IoList) ->
case inet:ifget("192.168.0.100", [addr]) of
{ok, [{addr, Ip}]} ->
{ok, S} = gen_udp:open(5010, [{broadcast, true}]),
gen_udp:send(S, Ip, 6000, IoList),
gen_udp:close(S);
T ->
io:format("Bad interface name, or\~n"
"broadcasting not supported\~w~n",[T])
end.
listen() ->
{ok, _} = gen_udp:open(6000),
loop().
loop() ->
receive
Any ->
io:format("received:~p~n", [Any]),
loop()
end.