Skip to content

Instantly share code, notes, and snippets.

@yongboy
Created October 24, 2012 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yongboy/3945273 to your computer and use it in GitHub Desktop.
Save yongboy/3945273 to your computer and use it in GitHub Desktop.
tcp_server_app
-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