-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnm_tcp_send_process.erl
82 lines (68 loc) · 2.61 KB
/
nm_tcp_send_process.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
-module(nm_tcp_send_process).
-export([tcp_send_process_loop/1]).
-include("nm_message_types.hrl").
tcp_send_process_loop(Socket) ->
Timeout = 180 * 1000,
receive
detach_resp->
io:format("Server: Detached ~n", []),
Reply = nm_messages:detach_resp(),
io:format("Server replying = ~p~n",[Reply]),
gen_tcp:send(Socket, Reply);
{attach_resp, Username, Password}->
io:format("Server: Client attached with name ~p and password ~p ~n", [Username, Password]),
Reply = nm_messages:attach_resp(),
io:format("Server: sends ~p~n",[Reply]),
gen_tcp:send(Socket, Reply);
{setup_resp, Username, PeerUsername}->
io:format("Server: Client ~p successfully connects to client ~p ~n", [Username, PeerUsername]),
Reply = nm_messages:setup_resp(),
io:format("Server: sends ~p~n",[Reply]),
gen_tcp:send(Socket, Reply);
{attach_rej,ErrorReason} ->
Reply = nm_messages:attach_rej(ErrorReason),
io:format("Server replying = ~p~n",[Reply]),
gen_tcp:send(Socket, Reply);
{setup_rej,ErrorReason} ->
Reply = nm_messages:setup_rej(ErrorReason),
io:format("Server replying = ~p~n",[Reply]),
gen_tcp:send(Socket, Reply);
link_lock_req ->
Reply = nm_messages:link_lock_req(),
io:format("Server initiating = ~p~n",[Reply]),
gen_tcp:send(Socket, Reply);
release_resp ->
Reply = nm_messages:release_resp(),
io:format("Server: sends ~p~n",[Reply]),
gen_tcp:send(Socket, Reply);
{release_rej, ErrorReason} ->
Reply = nm_messages:release_rej(ErrorReason),
io:format("Server replying = ~p~n",[Reply]),
gen_tcp:send(Socket, Reply);
{link_start_ind, Ref}->
io:format("Server: Start link with ref ~p ~n", [Ref]),
Reply = nm_messages:link_start_ind(Ref),
io:format("Server: sends ~p~n",[Reply]),
gen_tcp:send(Socket, Reply);
link_stop_ind->
io:format("Server: Stop link ~n"),
Reply = nm_messages:link_stop_ind(),
io:format("Server: sends ~p~n",[Reply]),
gen_tcp:send(Socket, Reply);
{punch_start_ind,ToIP, ToPort}->
io:format("Server: Punch_start_ind to IP ~p, to Port ~p~n", [ToIP,ToPort]),
Reply = nm_messages:punch_start_ind(ToIP, ToPort),
io:format("Server: sends ~p~n",[Reply]),
gen_tcp:send(Socket, Reply);
punch_stop_ind->
io:format("Server: Punch_stop_ind ~n", []),
Reply = nm_messages:punch_stop_ind(),
io:format("Server: sends ~p~n",[Reply]),
gen_tcp:send(Socket, Reply)
after
Timeout ->
Reply = nm_messages:keep_alive_ind(),
io:format("Server: sends ~p ~n",[Reply]),
gen_tcp:send(Socket, Reply)
end,
tcp_send_process_loop(Socket).