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
|
%%%-------------------------------------------------------------------
%%% @author Joe Zhao
%%% @copyright (C) 2014, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 26. 四月 2014 16:34
%%%-------------------------------------------------------------------
-module(startserv).
-author("Joe Zhao").
-compile([debug_info]).
%% API
-export([start/0,startmon/0,mon/0]).
mon() ->
process_flag(trap_exit,true),
Pid = spawn_link(tcpport,start,[5575]),
receive
{_,shutdown} -> Pid ! shutdown;
{'EXIT',Pid,normal} -> ok;
{'EXIT',Pid,shutdown} -> ok;
{'EXIT',Pid,_} -> mon()
end.
startmon() ->
spawn(?MODULE,mon,[]).
start() ->
PPid=startmon(),
timer:sleep(100),
Pid=portman:start({"localhost",5575}),
portman:send(Pid,["Something 1"]),
timer:sleep(100),
portman:send(Pid,["Something 2"]),
timer:sleep(100),
portman:send(Pid,["Something 3"]),
timer:sleep(100),
portman:send(Pid,["Something 4"]),
timer:sleep(100),
portman:send(Pid,shutdown),
PPid ! {self(),shutdown}.
|