[erlang-questions] How to write a generic IRC client the OTP way?

Mazen Harake <>
Thu Jun 30 08:38:15 CEST 2011


Try eirc here: https://github.com/mazenharake/eirc

Trying to do synchronous IRC is doomed to fail imho. eirc sends a
message everytime you get an event/response and by keeping your own
state you put context to these events to know what they mean. IRC
wasn't really made for computer programs but rather for a telnet
prompt so that is why this protocol is flawed in many ways (but very
easy).

eirc is under the 2-clause BSD license so do what ever you want with it.

On 30 June 2011 04:06, Ale <> wrote:
> Hello All,
>
> As a learning experience I want to make a generic IRC client. My
> question is regarding the path to genericness, what would be the right
> way to do this, or the OTP way?
>
> At first I thought that I could use gen_server to hide logic there. A
> client would call gen_server:call(ircclient, {nick, ale}) to set the
> nickname for example. Since call is synchronous, and setting the nick
> in irc, might take a couple of (micro)seconds, the process calling
> will have to wait until it receives an answer and the client (calling
> gen_server) might loose some interactivity (or the ability to do
> something else while the response of the "NICK" irc command comes
> back)
>
> The next thought was to use gen_server:cast(ircclient, {nick, ale}),
> but then how would the client would get the response? As far as I
> understood there is no way to get a deferred reply from gen_server.
> The calling process has to wait, even if we use gen_server:call with
> norepley and then gen_server:reply (which as far as I understood it is
> useful, when making the gen_server container or process non blocking).
>
> I could pass a callback function to gen_server:call, like this
> gen_server:cast(ircclient, {nick, ale, fun CallbackFun/1}), and
> CallbackFun takes the result and does something with it. This migh
> work, but then that doesn't look very "OTP" to me.
>
> This is what I'm having trouble the most understanding if "gen_*"
> processes can call back in a deferred manner to the client using the
> "gen_*" process.  "Hey gen_server, call me back when you get this
> done".
>
> Probably my design is wrong?
>
> Finally researching a bit, I thought that it might be a good idea to
> write a behaviour. But the same question comes up, how do I callback
> the client? (diagram: http://i.imgur.com/6N6Je.png)
>
> Hopefully I explained my problem, and questions.
>
> Thanks,
>
> Regards,
> --
> Ale.
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list