Standby system handover

Chaitanya Chalasani chaitanya.chalasani@REDACTED
Fri Jul 7 12:16:27 CEST 2006


Hi,

We currently have a non-realtime standby server for our mission critical 
application. In our struggle to make a realtime standby system my job is to 
develop an application that does TCP/IP packet forwarding to the active 
server and in an event of active server unavailability it would send the 
packet to any of the configured standby server. The application is not 
written in erlang, but I am planning to write the soft handover application 
in erlang. I am attaching a test module for the same which serves the purpose 
but I wanted to know a better design for the same or any feature in 
erlang/OTP that can help me build more robust application.

-- 
CHAITANYA CHALASANI 
LINUX USER #410931
-------------- next part --------------
-module(routerApp).
-compile(export_all).


listener(PortOwn,ClusterList) ->
    case gen_tcp:listen(PortOwn,[binary,{packet,0},{keepalive,true},{reuseaddr,true}]) of
        {ok,LSock} -> 
        	acceptConnections(LSock,ClusterList),
			gen_tcp:close(LSock),
			listener(PortOwn,ClusterList);
		Other ->
			io:format("Received ~p~n",[Other])
	end.

acceptConnections(LSock,ClusterList) ->
    case gen_tcp:accept(LSock) of
        {ok,Sock} ->
            Pid = spawn(routerApp,clientConnectionThread,[Sock,ClusterList]),
            gen_tcp:controlling_process(Sock,Pid ),
            acceptConnections(LSock,ClusterList);
        {error,Reason} ->
            io:format("Unknown error ~p~n",[Reason]);
        Other ->
            io:format("Unknown responce ~p~n",[Other])
    end.

clientConnectionThread(Sock,[{Ipaddress,Port}|ClusterList]) ->
    case gen_tcp:connect(Ipaddress,Port ,[binary,{active,true}] ) of
        {ok,ClustSock} ->
            case listenForMessages(Sock,ClustSock) of
                {error,clusterNodeClosed} ->
                    clientConnectionThread(Sock,ClusterList++[{Ipaddress,Port}]);
                {error,clientClosed} ->
                	io:format("Client Closed and so parallel thread dieing~n");
                Other ->
                    io:format("Unknown error ~p and so parallel thread dieing~n",[Other])
            end;
        Other1 ->
            io:format("Received ~p while connecting to ~p ~n",[Other1,{Ipaddress,Port}] ),
            clientConnectionThread(Sock,ClusterList++[{Ipaddress,Port}])
    end.
                
listenForMessages(Sock,ClustSock) ->
    receive
		{tcp_closed,ClustSock} ->
            gen_tcp:close(ClustSock),
            gen_tcp:close(Sock),
            {error,clientCloses};
			%{error,clusterNodeClosed};
        {tcp_closed,Sock} ->
            gen_tcp:close(Sock),
            gen_tcp:close(ClustSock),
            {error,clientClosed};
        {tcp,ClustSock,Data} ->
            io:format("Received ~w from server socket~n",[Data]),
            gen_tcp:send(Sock,Data ),
			listenForMessages(Sock,ClustSock);
        {tcp,Sock,Data} ->
            io:format("Received ~w from client socket~n",[Data]),
            gen_tcp:send(ClustSock,Data ),
            listenForMessages(Sock,ClustSock);
        Other ->
            io:format("Received unknown info ~p~n",[Other]),
            {error,unknown}
	end.   


More information about the erlang-questions mailing list