fix
This commit is contained in:
parent
cfedc75e1e
commit
41a50c04cc
@ -92,7 +92,7 @@ start_udp_server() ->
|
||||
{ok, Props} = application:get_env(iot, udp_server),
|
||||
Port = proplists:get_value(port, Props),
|
||||
UdpOpts = [{udp_options, [binary, {reuseaddr, true}]}],
|
||||
{ok, _} = esockd:open_udp(iot_udp_server, Port, UdpOpts, {iot_udp_server, start_link, []}),
|
||||
{ok, _} = esockd:open_udp(iot_udp_server, Port, UdpOpts, {iot_udp_handler, start_link, []}),
|
||||
lager:debug("[iot_app] the udp server start at: ~p", [Port]).
|
||||
|
||||
%% 启动内存数据库
|
||||
|
||||
27
apps/iot/src/iot_udp_handler.erl
Normal file
27
apps/iot/src/iot_udp_handler.erl
Normal file
@ -0,0 +1,27 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @author aresei
|
||||
%%% @copyright (C) 2023, <COMPANY>
|
||||
%%% @doc
|
||||
%%%
|
||||
%%% @end
|
||||
%%% Created : 31. 8月 2023 13:48
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(iot_udp_handler).
|
||||
-author("aresei").
|
||||
|
||||
%% API
|
||||
-export([start_link/2, loop/2]).
|
||||
|
||||
start_link(Transport, Peer) ->
|
||||
{ok, spawn_link(?MODULE, loop, [Transport, Peer])}.
|
||||
|
||||
loop(Transport = {udp, Server, _Sock}, Peer) ->
|
||||
receive
|
||||
{datagram, Server, <<Len:16, HostUUID:Len/binary>>} ->
|
||||
lager:debug("[iot_udp_server] peer: ~p, get heartbeat of: ~p", [esockd:format(Peer), HostUUID]),
|
||||
Pid = iot_host:get_pid(HostUUID),
|
||||
iot_host:heartbeat(Pid),
|
||||
loop(Transport, Peer);
|
||||
{datagram, Server, _} ->
|
||||
exit(normal)
|
||||
end.
|
||||
Loading…
x
Reference in New Issue
Block a user