erlang

Erlang开发MMO的一些思考

孤人 提交于 2019-12-06 08:21:51
最近混了一些群,发现用erlang做页游的越来越多了,时不时的还有人站出来让新手去学erlang。 不过主要还是应用于页游后端,游戏逻辑简单的就可以一试。还未见到有实时的MMORPG采用erlang作为后台。 原因不外乎端游几乎是C++一脉相承,从客户端延伸到服务端,当然是同种语言方便。此外计算性能和员工招聘也是重要的理由。 而页游和手游的客户端往往采用flash,java,objectc等,除java外都很少用于服务端开发,所以服务端语言的选择就有了更多自由。 早两年erlang技术人员还很少,现在已经有一定的量了。出于兴趣,我重新考虑用erlang开发实时战斗的MMORPG的方法。 有利的部分 erlang是好的,吸引了很多人的兴趣。不少人甚至将erlang体系的影响带到了自己所在的其他语言项目中,构建一些类似erlang的基础设施。包括我。 随意挥霍的process。 端游从早期的单进程支持一个游戏服,发展到现在的多进程支持一个游戏服。其中涉及多个进程协作的逻辑越来越多,异步任务相互之间由于时间差带来的问题也越来越频繁。 通常我总会利用状态机或者类似的办法管理异步任务,但并不能顾及到每一处,而且状态机增加了理解代码的难度。 erlang轻量的process使我能为每个异步任务创建一个独立的执行过程,同时变量不可变的机制几乎消除了多线程中的资源共用的问题。 发送消息太简单。

URL encode in Erlang and Cyrillic

若如初见. 提交于 2019-12-06 08:15:42
问题 I'm using standard httpc client in erlang, for sending/receiving request to some service. Sometimes I have a Cyrillic path in my URL. How can I URL-encode Cyrillic URLs? Thank you. 回答1: ~/erl$erl Erlang R14B04 (erts-5.8.5) [source] [64-bit] [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false] Eshell V5.8.5 (abort with ^G) 1> Encoded = edoc_lib:escape_uri("абвгдеё"). "%c0%b0%c0%b1%c0%b2%c0%b3%c0%b4%c0%b5%c1%91" 2> http_uri:decode(Encoded). [192,176,192,177,192,178,192,179,192,180,192

Elixir compile-time code injection / AOP

半腔热情 提交于 2019-12-06 07:58:19
问题 I've previously used AOP-style code to separate Logic from Logging, and been very pleased with the results. I recognize that opinions on AOP vary, but I'd like to figure out a solution in Elixir, even if I don't end up using it in prod. The closest example I've seen is the setup callback inside of ExUnit, which allows execution of code before each test runs; I'd like to do something similar, but haven't been able to muddle through the ExUnit source to grasp the intuitions there. In code form:

Erlang: How to pipe stdin input from a file to an erlang program and match eof?

社会主义新天地 提交于 2019-12-06 07:56:46
问题 How to pipe input from a file as stdin to an erlang program running in the shell as well as standalone? I have a file hr.erl and I compile it from the shell. There is a function in it which accepts input from stdin using io:fread() . I have written a case expression with guards where if it matches {ok, [0]} it should terminate. Instead of 0 , I actually need it to be eof . How to send eof when running in a shell? I have a file inp.txt with values 1 2 3 and 0 on each line. How can I pass it

Mapreduce with Riak

不问归期 提交于 2019-12-06 07:53:40
问题 Does anyone have example code for mapreduce for Riak that can be run on a single Riak node. 回答1: cd ~/riak erl -name zed@127.0.0.1 -setcookie riak -pa apps/riak/ebin In the shell: # connect to the server > {ok, Client} = riak:client_connect('riak@127.0.0.1'). {ok,{riak_client,'riak@127.0.0.1',<<6,201,208,64>>}} # create and insert objects > Client:put(riak_object:new(<<"groceries">>, <<"mine">>, ["eggs", "bacons"]), 1). ok > Client:put(riak_object:new(<<"groceries">>, <<"yours">>, ["eggs",

extending ejabberd with modules for custom mysql schema?

…衆ロ難τιáo~ 提交于 2019-12-06 07:52:55
Instead of ejabberd.sql ,I am using a custom MySQL schema(because of legacy reasons). I will be doing some DB operations on certain activities like Ping,Pong,Msg deliverd,Msg read and most importantly getting/setting roster list and announcing presence(all of these on my own schema). However,ejabberd seems to use ejabberd.sql all throughout and its source code is pretty much dependent on it.Fiddling with the source code is the last thing I would do since I am not aware of its dependencies. Possible ideas : Lets say if I extend ejabberd by writing my own modules,then what use will mod_roster

Erlang 17 recommend to use map replace record,but how to make mnesia support map?

随声附和 提交于 2019-12-06 07:48:26
问题 In joe's "Big changes to Erlang" http://joearms.github.io/2014/02/01/big-changes-to-erlang.html "we wanted maps to be a replacement for records and to be as efficient as records, and its not blindingly obvious how to do so." How to make transform records to maps in mnesia? 回答1: Mnesia uses ETS (and dets) internally and these are based on tuples as the base data structure. While they can contain maps at the top-level it must be tuples. As records are tuples records can also be at the top-level

Setting up RabbitMQ cluster on Windows servers

此生再无相见时 提交于 2019-12-06 07:40:58
问题 I am trying to set up a RabbitMQ cluster on Windows servers, and this requires using shared Erlang cookie file. According to the documentation, all I need to do is to ensure that the root directories on different machines contain the same .erlang.cookie file. So what I did is found these files on both machines and overwrote them with the same shared version. After that all rabbitmqctl commands failed on the machine with new file version with "unable to connect to node..." error message. I

passing runtime arguments to erlang when running rebar eunit

Deadly 提交于 2019-12-06 07:35:00
In my startup script, I am starting erlang with: erl -args_file vm.args Currently, while trying to run unit tests with rebar eunit is there a way for me to pass custom runtime arguments such as the -args_file option to the erlang process that rebar kicks off? I have searched docs high and low to no avail... I appreciate the help. I answered my own question. I use the ERL_FLAGS variable to pass command line args. Here is a snippet from my Makefile: ERL_FLAGS="-args_file test/conf/vm.eunit.args" ./rebar skip_deps=true eunit The first method is satisfied with your restriction: 1. in your eunit

How to know when user redirect output from erlang shell into a file

半城伤御伤魂 提交于 2019-12-06 07:34:23
问题 I have an sample module -module(helloworld). -compile(export_all). main() -> io:format("~s~s~s~n",["\e[31m","Hello world!","\e[0m"]). When I build: erlc helloworld.erl After that, I run: erl -noshell -s helloworld main -s init stop Hello world! (with red color) erl -noshell -s helloworld main -s init stop > text.txt ^[[31mHello world!^[[0m (The content in text.txt is ugly, so I don't like). My problem is: How to know when user redirect output from erlang shell into a file? How can I write to