erlang

Cannot spawn an erlang supervisor from the shell

放肆的年华 提交于 2019-12-10 15:49:12
问题 I've implemented a gen_server and supervisor: test_server and test_sup . I want to test them from the shell/CLI. I've written their start_link functions such that their names are registered locally. I've found that I can spawn the test_server from the command line just fine, but a spawned test_sup does not allow me to interact with the server at all. For example, I can spawn a test_server by executing: 1> spawn(test_server, start_link, []). <0.39.0> 2> registered(). [...,test_server,...] I

How to Integrate FCM with Ejabberd?

瘦欲@ 提交于 2019-12-10 15:39:34
问题 Environment: Ejabberd Version : 16.04 Smack-android-4.1.0 I have created an Android chat application with a XMPP server. However due to Google play permission issue I had to narrow down the feature from app which supported receiving incoming message notifications when the app is in the background. As an alternative I received the following suggestion from GooglePlay Review Team. Once you’ve removed this permission, you might consider using Firebase Cloud Messaging (FCM) if your app’s message

In Erlang, when a process's mailbox growth bigger, it runs slower, why?

匆匆过客 提交于 2019-12-10 15:35:13
问题 Here is the example:test_for_gen_server.erl When a process got 10000 messages in its mailbox, it took 0.043 sec to finish. When the number is 50000, it should take 0.215 sec, but the reality is 2.4 sec, 10 times slower. Why? Erlang/OTP 18 [erts-7.1] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:true] Eshell V7.1 (abort with ^G) 1> test_for_gen_server:start_link(). {ok,<0.36.0>} 2> test_for_gen_server:test(10000). ok ======gen_server: Times:10000 Cost:42863 3> test_for_gen

How to debug erlang code during rebar3 eunit?

微笑、不失礼 提交于 2019-12-10 15:22:40
问题 I have created an release app with rebar3 (beta-4). Added some eunit tests and wrote some code. For now I have to debug one test case to see what I have to add to make the implementation to work properly. I found some articles about using dbg from erlang console and I found how to write debug info from eunit. But I need to get info from code that I have to test (the actual implementation(logic)). Is there a way to debug erlang code (actual source code, not the test one) when rebar3 is used

Elixir - sum of list values with recursion

我的梦境 提交于 2019-12-10 14:56:24
问题 Just trying to do simple sum of list values. defmodule Mth do def sum_list([]) do 0 end def sum_list([H|T]) do H + sum_list(T) end end IO.puts Mth.sum_list([1, 2, 300]) But I get this error: **(FunctionClauseError) no function clause matching in Mth.sum_list/1 pokus.ex:3: Mth.sum_list([1, 2, 300]) pokus.ex:14: (file) (elixir) src/elixir_lexical.erl:17: :elixir_lexical.run/2 (elixir) lib/code.ex:316: Code.require_file/2** 回答1: You need to use lowercase letters for variable and functions names.

Erlang: simple refactoring

十年热恋 提交于 2019-12-10 14:28:29
问题 Consider the code: f(command1, UserId) -> case is_registered(UserId) of true -> %% do command1 ok; false -> not_registered end; f(command2, UserId) -> case is_registered(UserId) of true -> %% do command2 ok; false -> not_registered end. is_registered(UserId) -> %% some checks Now imagine that there are a lot of commands and they are all call is_registered at first. Is there any way to generalize this behavior (refactor this code)? I mean that it's not a good idea to place the same case in all

Erlang: variable is unbound

放肆的年华 提交于 2019-12-10 14:24:57
问题 Why is the following saying variable unbound? 9> {<<A:Length/binary, Rest/binary>>, Length} = {<<1,2,3,4,5>>, 3}. * 1: variable 'Length' is unbound It's pretty clear that Length should be 3. I am trying to have a function with similar pattern matching, ie.: parse(<<Body:Length/binary, Rest/binary>>, Length) -> But if fails with the same reason. How can I achieve the pattern matching I want? What I am really trying to achieve is parse in incoming tcp stream packets as LTV(Length, Type, Value).

Why doesn't Erlang come with a decent package management system like gem? [closed]

放肆的年华 提交于 2019-12-10 14:20:08
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . Ok, this sounds like a bit of a rant, but I was wondering if there was a technical reason that Erlang doesn't have a proper package management system by default. 回答1: No major technical reason really. Just different needs as the classic way of setting up and installing erlang

Erlang: Finding my IP Address

六眼飞鱼酱① 提交于 2019-12-10 13:56:35
问题 I'm attempting to complete a Load Balancer / Login Server / Game Server setup using Redis for some parts. Load balancing is one of them. In my Redis load balancing instance I'm using ordered sets. The key is the application name, the members are the IP addresses of the game servers. Herein lies my issue. I would like to use a public method within erlang. I cannot find anything that fits my needs. I'm wondering if I'm over looking something. {ok, L} = inet:getif(), IP = element(1, hd(L)),

Unable to use Erlang/ets in receive block

半城伤御伤魂 提交于 2019-12-10 13:45:06
问题 I am trying to use Erlang/ets to store/update various informations by pattern matching received data. Here is the code start() -> S = ets:new(test,[]), register(proc,spawn(fun() -> receive_data(S) end)). receive_data(S) -> receive {see,A} -> ets:insert(S,{cycle,A}) ; [[f,c],Fcd,Fca,_,_] -> ets:insert(S,{flag_c,Fcd,Fca}); [[b],Bd,Ba,_,_] -> ets:insert(S,{ball,Bd,Ba}) end, receive_data(S). Here A is cycle number, [f,c] is center flag , [b] is ball and Fcd,Fca, Bd, Ba are directions and angle of