%%%------------------------------------------------------------------- %%% @author Joe Zhao %%% @copyright (C) 2014, %%% @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}.