We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents a32f699 + 87ccd6d commit fb0e57bCopy full SHA for fb0e57b
1 file changed
lib/dns/server.ex
@@ -21,19 +21,23 @@ defmodule DNS.Server do
21
end
22
23
def init([port]) do
24
- socket = Socket.UDP.open!(port, as: :binary, mode: :active)
+ {:ok, socket} = :gen_udp.open(port, [{:active, true}, {:mode, :binary}])
25
IO.puts("Server listening at #{port}")
26
27
# accept_loop(socket, handler)
28
{:ok, %{port: port, socket: socket}}
29
30
31
- def handle_info({:udp, client, ip, wtv, data}, state) do
+ def handle_info({:udp, client, ip, port, data}, state) do
32
record = DNS.Record.decode(data)
33
response = handle(record, client)
34
- Socket.Datagram.send!(state.socket, DNS.Record.encode(response), {ip, wtv})
+ :gen_udp.send(state.socket, convert_address(ip), port, DNS.Record.encode(response))
35
{:noreply, state}
36
37
+
38
+ defp convert_address(a) when is_binary(a), do: String.to_charlist(a)
39
40
+ defp convert_address(a), do: a
41
42
43
0 commit comments