Suggested Example
Steve Elkins
sgelkins@REDACTED
Tue Oct 10 05:15:32 CEST 2000
Ulf Wiger wrote:
>
> On Fri, 6 Oct 2000, Jeffrey Straszhiem wrote:
...
> >difficulty figuring out the OTP framework for applications,
> >supervisors, gen_server's and such.
>
> I agree that this is a problem.
>
> >I understand the difficulty of putting a tutorial like this
> >together, and don't expect to see anything on that order soon.
> >However, it would be nice to have a simple, but fairly complete,
> >Erlang application to look at -- and by that I mean a skeleton of
> >one. I know I could look at Mnesia or something, but I'd rather
> >focus all of my meager understanding on figuring out the OTP
> >structures instead of the specifics of the database.
Ok, I've figured out most of these issues and have attached a tgz
containing 2 embarrassingly simple apps, as well as a perl script
from the Cookbook that exercises one of them.
One app, dshb, does nothing at all interesting. Skeletal. ;-)
The other, cosb, is slightly more complicated. It has a special
process that listens on a UDP port and notifies a gen_event example
when it receives something. The event handler replies. Simple.
To play with it...
1. tar zxvf ctii.tgz
2. cd ctii
3. erl -sname xyz -boot start_sasl -pa ./cosb/ebin -pa ./dshb/ebin
4. application:start(cosb).
5. udpmsg localhost hi
6. if all's well, udpmsg should say it received "you said hi"
7. udp_spc.erl is a standalone echoer, straight from the Special
Processes chapter of Design Principles.
...assuming everyone can infer each step's context.
Summing up, dshb is a very skeletal app, cosb has a little meat, and
udp_spc is the forerunner of cosb. Supplemental reading would be
chapters 5, 7, and 8 of Design Principles, as well as the relevant
man pages. And sys:trace/2 is wonderful.
Great, so I can build *local* apps.
What's busting *my* chops is getting these apps to run distributed. I
could really use something as simple as what I've provided here, but
distributed. The particular place I'm stuck right now is getting a
proper .boot together, since various messages in the archives have led
me to think I can't just do something like step 4 above and hope for
distribution, takeover, etc. systools:script2boot/1 says ok, but when
I try...
sge:219$ erl -boot start_cosb
{'init terminating in do_boot',{'can not load',erlang,get_file}}
init terminating in do_boot ()
sge:220$
I even ripped out all my stuff so my .script looks like the start_sasl
one, but still the error. Is it where I'm doing script2boot?
<sigh> I realize this is only the 1st hurdle. Any advice at all on
the general subject of building distributed apps would be greatly
appreciated.
Thanks,
Steve
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ctii.tgz
Type: application/octet-stream
Size: 18121 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20001009/c8e3f919/attachment.obj>
-------------- next part --------------
#!/usr/bin/perl -w
# udpmsg - send a message to the udpquotd server
use IO::Socket;
use strict;
my($sock, $server_host, $msg, $port, $ipaddr, $hishost,
$MAXLEN, $PORTNO, $TIMEOUT);
$MAXLEN = 1024;
$PORTNO = 5151;
$TIMEOUT = 5;
$server_host = shift;
$msg = "@ARGV";
$sock = IO::Socket::INET->new(Proto => 'udp',
PeerPort => $PORTNO,
PeerAddr => $server_host)
or die "Creating socket: $!\n";
$sock->send($msg) or die "send: $!";
eval {
local $SIG{ALRM} = sub { die "alarm time out" };
alarm $TIMEOUT;
$sock->recv($msg, $MAXLEN) or die "recv: $!";
alarm 0;
1; # return value from eval on normalcy
} or die "recv from $server_host timed out after $TIMEOUT seconds.\n";
($port, $ipaddr) = sockaddr_in($sock->peername);
$hishost = gethostbyaddr($ipaddr, AF_INET);
print "Server $hishost responded ``$msg''\n";
More information about the erlang-questions
mailing list