[erlang-questions] Erlang beginner questions

Lukas Larsson lukas.larsson@REDACTED
Wed Apr 13 15:45:56 CEST 2011

For a generic tcp server library I would also recommend looking at http://github.com/oscarh/gen_tcpd. It (IMO) solves the tcp server problem beautifully and does not force you into a gen_server.  It also support multiple acceptors and ssl connections.

----- Original Message -----
From: "Mihai Balea" <mihai@REDACTED>
To: "Mode7James" <James@REDACTED>
Cc: erlang-questions@REDACTED
Sent: Wednesday, April 13, 2011 3:12:22 PM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna
Subject: Re: [erlang-questions] Erlang beginner questions

On Apr 13, 2011, at 3:17 AM, Mode7James wrote:
> 1) gen_server is a behavior.  It's a little confusing that gen_udp and
> gen_tcp are both modules, but use the same naming conventions.   I've seen
> quite a few documents on how one uses "gen_server" as a behavior - is there
> any that actually show what the text file looks like?  Can I create my own
> behaviors?  I come from a flash background (Java) so I'm very familiar with
> interfaces.  Can one module implement multiple behaviors, or is it only
> one-to-one direct relationship?  Is there somewhere that I can see the
> complete master list of built-in OTP behaviors and what they do?

Think of behaviours as interfaces, although they are not strictly enforced.
You can define your own, here's an example: http://www.trapexit.org/Defining_Your_Own_Behaviour

gen_udp and gen_tcp (and gen_sctp) are not, strictly speaking, behaviours. I've always wondered why they are named that way.

The big 5 are gen_server, gen_fsm, gen_event, supervisor and application. The vast majority of OTP compliant code that I've seen is built on these five.

You can have a module implement multiple behaviours, just be careful about callback clashes 

> 2) In the 20bits article, how is the port number generated?  Are port
> numbers unique to an application, or are there different port numbers for
> different protocols?  Is this secure?  How do Erlang services deal with DDOS
> attacks?  Are there any tried-and-true methods that are used?

The 20bits article is pretty good, but I'd recommend using gen_nb_server for building tcp servers.
You can find it here: https://github.com/kevsmith/gen_nb_server
It is a 3rd party behaviour for building performant, non-blocking tcp servers

> 3) Can someone log in via TCP connection, authenticate credentials upgrading
> to SSL, and then also open a UDP connection for the gameplay mechanics?

Yes, that's probably doable, but you'd have to be more specific as to what exactly want to do.
For example, there's not such thing as a "udp connection". You can fire off UDP packets to anywhere, if there's someone listening, they'll get them, otherwise they'll be dropped.
Do you want to open one UDP port for each authenticated user or have all of them send data to a single, common UDP port?

> 4) I've read that distributed Erlang is using "all or nothing" security, ie
> nodes with access can essentially do whatever they want.  Is there a way to
> keep a service running on a dedicated server, and remotely hotswap code via
> my macbook?  Any examples of this being done?

As long as you have shell access to your remote server, you can certainly do hot updates


erlang-questions mailing list

More information about the erlang-questions mailing list