erlang

Erlang needs to connect to https server?

China☆狼群 提交于 2019-12-23 03:22:14
问题 I have an erlang application and it needs to connect to a php application hosted on Apache with HTTPS. How do I install the client certificate on my erlang machine? 回答1: The SSL module of Erlang/OTP which is the interface for Secure Socket Layer has an option for defining client side certificate: {cacertfile, path()} Path to a file containing PEM-encoded CA certificates. The CA certificates are used during server authentication and when building the client certificate chain. Now if you want

What's the right way to use erlang mongodb driver to make a db action?

旧街凉风 提交于 2019-12-23 03:14:04
问题 I am trying official mongodb erlang driver. I read the doc and there's still something I can't understand. Hope anyone can tell me what's the right way to use it: Every time I make an action, I just write something as follows: {ok, Conn} = mongo:connect ({localhost, 27017}). mongo:do (safe, master, Conn, test, fun() -> mongo:save (foo, {'_id', 1, bbb,22, y,2}), mongo:save (foo, {'_id', 4, bbb,22, y,2}) end). mongo:disconnect(). Is this a right way? Everytime I finished a db action, Conn seems

value in a recursive loop

吃可爱长大的小学妹 提交于 2019-12-23 02:54:09
问题 In a recursive loop, I would like to change the value of a variable: loop(N) when N > ... -> N; loop(N) -> case ... of N+1 ... end, ... case ... of N-1 ... end, ... loop(N). How to "pass" the new value of N ? 回答1: Since you can't change the value of N once assigned, you need to call loop with the new value: loop(N) -> loop(N+1). Alternatively, create a temporary variable to hold its new value before passing it into the recursive loop invocation. loop(N) -> NewN = N+1, loop(NewN). If this

Installing Yaws server on Ubuntu 12.04 (Using a cloud service)

假如想象 提交于 2019-12-23 02:45:23
问题 I'm trying to get a Yaws web server working on a cloud service (Amazon AWS). I've compilled and installed a local copy on the server. My problem is that I can't get Yaws to run while running on either port 8000 or port 80. I have the following configuration in yaws.conf: port = 8000 listen = 0.0.0.0 docroot = /home/ubuntu/yaws/www/test dir_listings = true This produces the following successful launch/result: Eshell V5.8.5 (abort with ^G) =INFO REPORT==== 16-Sep-2012::17:21:06 === Yaws: Using

How do I reset/clear erlang terminal

喜夏-厌秋 提交于 2019-12-23 02:33:05
问题 I'm trying to get the prompt reset, forget all the variables and start the prompt from line 1> I'm aware of the following built-in functions f(). %% forget all io:format("\e[H\e[J"). %% "clear screen" and moving cursor to the begin of the line but when I'm writing the following commands, it does forget all the variables, but it doesn't "reset" the screen, just clear the screen, like clear command in the terminal. in Linux, I just type reset , but I couldn't find equivalent command or built in

How to read erlang term from redis by using java client?

ε祈祈猫儿з 提交于 2019-12-23 02:25:13
问题 e.g. I save the tuple T = {k1, v1, k2, v2} to the redis by jedis: eredis:q(Conn, ["SET", <<"mykey">>, term_to_binary(T)]). I am trying to use the code below to read this erlang term: Jedis j = Redis.pool.getResource(); byte[] t = j.get("mykey").getBytes(); OtpInputStream ois = new OtpInputStream(t); System.out.println(OtpErlangObject.decode(ois)); The error is: com.ericsson.otp.erlang.OtpErlangDecodeException: Uknown data type: 239. So how can I get the erlang term correctly? Erlang side:

How does an Erlang gen_server start_link a gen_server on another node?

亡梦爱人 提交于 2019-12-23 02:04:41
问题 I have an Erlang application that is getting a little too resource-hungry to stay on one node. I'm in the process of making gen_servers move from one process to another - which turns out to be relatively easy. I'm at the last hurdle: getting the factory process that creates these gen_servers to spawn them on the remote node instead of the local one. The default behavior of start_link is clearly to start locally only, but I don't see any option to change that. It would seem that I'm going to

how to run ejabberd with Erlang on Heroku?

家住魔仙堡 提交于 2019-12-23 01:54:49
问题 I am trying to create a realtime private chat app running on ejabberd in Erlang. I am trying to install the same on Heroku. I am aware on how to run Erlang on Heroku but I don't know how to get ejabberd running on Heroku for my application. I am completely new in developing realtime chat app but I am thinking to make it scalable. Please anyone can tell me how to do this. Thanks. 回答1: Assuming that you are using source code form github. After compiling with ./autogen.sh ./configure make rel

Pagination search in Erlang Mnesia

送分小仙女□ 提交于 2019-12-23 01:28:19
问题 For example, given record -record(item, { id, time, status}). I want to search the 1000 to 1100 items, ordered by time and status =:= <<"finished">> Any suggestions? 回答1: It depends on what your queries look like. If you need to order by lots of different columns, then I'd consider using SQL instead of Mnesia. But if you only need the kind of query you described, you should be able to use the ordered_set type of table to handle the ordering and mnesia:select/4 to handle pagination and the

Allocating memory in Erlang C NIF

匆匆过客 提交于 2019-12-22 23:12:22
问题 Why would one use void *enif_alloc_resource(ErlNifResourceType* type, unsigned size) as opposed to void *enif_alloc(size_t size) when trying to allocate memory from an Erlang C NIF? Reference does not specify much as to why. http://www.erlang.org/doc/man/erl_nif.html#enif_alloc 回答1: enif_alloc_resource is used to create resources which are garbage collected by the vm when not used any more. enif_alloc works just like malloc, only is uses an Erlang VM specific implementation rather than the