Created
October 24, 2012 10:01
-
-
Save yongboy/3945273 to your computer and use it in GitHub Desktop.
tcp_server_app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(tcp_server_app). | |
-author('yongboy@gmail.com'). | |
-behaviour(application). | |
-export([start_client/1]). | |
-export([start/2, stop/1]). | |
-define(DEF_PORT, 2222). | |
%% A startup function for spawning new client connection handling FSM. | |
%% To be called by the TCP listener process. | |
start_client(Socket) -> | |
tcp_server_sup:start_child(Socket). | |
start(_Type, _Args) -> | |
ListenPort = get_app_env(listen_port, ?DEF_PORT), | |
tcp_server_sup:start_link(ListenPort, tcp_client_handler). | |
stop(_S) -> | |
ok. | |
get_app_env(Opt, Default) -> | |
case application:get_env(application:get_application(), Opt) of | |
{ok, Val} -> Val; | |
_ -> | |
case init:get_argument(Opt) of | |
[[Val | _]] -> Val; | |
error -> Default | |
end | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment