Tiliman’s Weblog

July 29, 2013

Viewing Erlang Crashdump Remotely

Filed under: Backend, Erlang — Tags: , , — tiliman @ 8:53 pm

Erlang allows you to load crashdump by using Crash Dump Viewer. The information provided has backtrace to figure out what went wrong and where. The catch is that default viewer only listens on 127.0.0.1 (localhost) ip address. There is no start method that takes IP address as a parameter to listen on. The way to make crash dump viewer to listen on other port is to start webtool before crash dump viewer and give it ip port.
Here is an example


1> webtool:start(standard_path,[{port,8888},{bind_address,{0,0,0,0}},{server_name,"mytest"}]).
WebTool is available at http://mytest:8888/
Or  http://0.0.0.0:8888/
{ok,}
2> crashdump_viewer:start().

or simply start webtool and browse to it and start crashdump viewer from the web GUI itself.

January 2, 2013

Google Cloud Messaging with Erlang

I have been working on Facebook matchmaking code for Android/Unity to mimic iOS Game Center like flow of match making where other player receives notification on phone. Server side is coded with Mochiweb in Erlang. Here is simple code to send GCM Notification.

 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
send_gcm_msg(ApiKey, Pnstoken, Message, Game) ->
        Baseurl = "http://android.googleapis.com/gcm/send",
        ApiKey1 = string:concat("key=",ApiKey),
        %% Create Json struct
        Body = lists:flatten(mochijson:encode({struct, [{registration_ids,{array, [Pnstoken]}},
                        {data,{struct, [{message,Message},{game,Game}]}},
                        {time_to_live,3600},
                        {collapse_key,game_invite}]})),
        try httpc:request(post, {Baseurl,[{"Authorization",ApiKey1}],"application/json",Body},[],[]) of
                {ok, {{_,200,_},_,RespBody}} ->
                        {ok, mochijson:decode(RespBody)};
                {error, Reason } ->
                        {error, Reason};
                {ok, {{StatusLine,_,_},_,RespBody}} ->
                        {error, {StatusLine, RespBody}};
                BigError -> {error, BigError}
        catch
                Throw -> {error, caught, Throw}
        end.

Create a free website or blog at WordPress.com.