erlang

How do I handle a WebSocket close from the client in Yaws?

不问归期 提交于 2019-12-08 03:47:40
问题 I have implemented a simple appmod that handle WebSockets and echo back the messages. But how do I handle an ws.close(); from the JavaScript client? I have tried with the code below, but handle_message({close, Reason}) is never called and ws.onclose = function(evt) {} is never executed on the JavaScript client. When I use the same JavaScript client code interacting with a node.js websocket, the client receives an onclose event immediately after ws.close(); . Here is the code for my simple

Erlang read post request

江枫思渺然 提交于 2019-12-08 03:40:36
问题 I'm trying to build a simple web server based on Erlang, so far I'm able to start a server with below code. tutorial ref -module(helloworld). -export([ main/1, run_server/0, start/0, service/3, ]). main(_) -> start(), receive stop -> ok end. run_server() -> ok = inets:start(), {ok, _} = inets:start(httpd, [ {modules, [ mod_alias, mod_auth, mod_esi, mod_actions, mod_cgi, mod_dir, mod_get, mod_head, mod_log, mod_disk_log ]}, {port, 8000}, {server_name,"helloworld"}, {server_root,"/tmp"},

Erlang record expression ignored warning

痴心易碎 提交于 2019-12-08 03:36:47
问题 I have following code: Check#tab_info{login_errors = 0}, {ok, PID}; But i get warning when i try to compile it: the result of the expression is ignored (suppress the warning by assigning the expression to the _ variable) What's wrong? How can i fix it? Thank you. 回答1: Well, the compiler is telling you exactly what's wrong :) You create a new #tab_info record, but never bind it to any variable. The code is therefore meaningless and the compiler is telling you so. Changing the Check variable

RabbitMQ RPM installation failed on Red Hat Enterprise Linux 7.2 (even with erlang installed)

女生的网名这么多〃 提交于 2019-12-08 03:28:31
问题 In the homepage of RabbitMQ it says First install erlang Then install RabbitMQ by rpm --import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc yum install rabbitmq-server-3.6.3-1.noarch.rpm I installed erlang but when install RabbitMQ it failed, the error says Requires: erlang>=R16B-03 But I have already installed erlang 19.0 , what's the problem? Someone in other article suggested RabbitMQ doesn't support erlang 19.0 right now, then what should I do? I have already installed erlang

why doesn't this erlang code work?

旧时模样 提交于 2019-12-08 03:07:51
问题 fib(N)-> P1 = spawn(fun concFib:conFib/0), P2 = spawn(fun concFib:conFib/0), X=rpc(P1,N-2),Y=rpc(P2,N-1),X+Y. conFib()-> receive {Client,N} -> Client ! regfib(N) end. rpc(Pid,Request)-> case erlang:is_process_alive(Pid) of true -> begin Pid ! {self(),Request}, receive {Pid,Respond} -> Respond end end; false -> io:format("~w process is dead.",[Pid]) end. regfib(N)-> case N<2 of true -> 1; false -> regfib(N,1,1,1) end. regfib(N,N,X,_)-> X ; regfib(N,M,X,Y)-> regfib(N,M+1,X+Y,X). The idea is to

Erlang: erl shell hangs after building a large data structure

 ̄綄美尐妖づ 提交于 2019-12-08 03:06:24
问题 As suggested in answers to a previous question, I tried using Erlang proplist s to implement a prefix trie. The code seems to work decently well... But, for some reason, it doesn't play well with the interactive shell. When I try to run it, the shell hangs: > Trie = trie:from_dict(). % Creates a trie from a dictionary % ... the trie is printed ... % Then nothing happens I see the new trie printed to the screen (ie, the call to trie:from_dict() has returned), then the shell just hangs. No new

Parallel power set generation in Erlang?

痴心易碎 提交于 2019-12-08 02:15:44
问题 There is a lot of example implementations of generating a powerset of a set in Java, Python and others, but I still can not understand how the actual algorithm works. What are the steps taken by an algorithm to generate a power set P(S) of a set S? (For example, the power set of {1,2,3,4} is {{}, {1}, {2}, {1,2}, {3}, {1,3}, {2,3}, {1,2,3}, {4}, {1,4}, {2,4}, {1,2,4}, {3,4}, {1,3,4}, {2,3,4}, {1,2,3,4}}.) UPD: I have found this explanation, but still I don't get it. I am trying to understand

Filtering message packet's body in ejabberd

谁说胖子不能爱 提交于 2019-12-08 02:03:30
问题 I am trying to filter undesired messages in ejabberd. I took some direction from this post. Here is the function snippet which gets executed via filter_packet hook: check_stanza({_From, _To, #xmlel{name = StanzaType}} = Input) -> AccessRule = case StanzaType of <<"message">> -> ?DEBUG("filtering packet...~nFrom: ~p~nTo: ~p~nPacket: ~p~nResult: ", [_From, _To, Input]), Input %check_stanza_type(AccessRule, Input) end. The packet printed in log : {{jid,<<"test25">>,<<"localhost">>,<<

erlang on google app engine?

二次信任 提交于 2019-12-08 01:38:40
问题 I know python can be run on GAE what is different erlang and python in lay man term? can erlang run on google app engine ? 回答1: Erlang and Python are programming languages, and each language has one or more "runtimes" that allow you to run programs written in those languages. GAE supplies a Python runtime. GAE has no support for Erlang programs. 来源: https://stackoverflow.com/questions/1654759/erlang-on-google-app-engine

Erlang: Output Problem

浪尽此生 提交于 2019-12-07 22:58:10
问题 In my erlang web application, there is a list, which contains integers to be printed on the web page. But when the script executes, it prints this, instead of actual list, Please look at this Image showing characters for unicode codepoint 1, 1, 2, 3, 5, 8, whitespace, codepoint 15 How to format this to gain what I want? Target list is [1, 1, 2, 3, 5, 8, 13, 15] 回答1: You should do this: P = [1, 1, 2, 3, 5, 8, 13, 15], Show_on_page = io_lib:format("~p",[P]), Show_on_page. This will represent