[update: Joe Armstrong replied; see comments]
I’m having trouble running the lib_chan example from chapter 10 of Programming Erlang. Here’s what I’ve done, step by step. The console listings are from a machine running Ubuntu linux 7.04. I get similar results under OS X.
First, I downloaded the latest source code.
drc@dawn:~/erlang$ wget http://media.pragprog.com/titles/jaerlang/code/jaerlang-code.tgz
--18:43:49-- http://media.pragprog.com/titles/jaerlang/code/jaerlang-code.tgz
=> `jaerlang-code.tgz'
Resolving media.pragprog.com... 207.7.108.187
Connecting to media.pragprog.com|207.7.108.187|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1,326,401 (1.3M) [text/plain]
100%[=========================================================================>] 1,326,401 402.03K/s ETA 00:00
18:43:57 (341.37 KB/s) - `jaerlang-code.tgz' saved [1326401/1326401]
drc@dawn:~/erlang$ tar -zxf jaerlang-code.tgz
drc@dawn:~/erlang$ ls
code/ jaerlang-code.tgz
As per Joe’s suggestion here, I run make.
drc@dawn:~/erlang$ cd code/ drc@dawn:~/erlang/code$ make erlc -W a.erl erlc -W b.erl erlc -W checker.erl ./checker.erl:39: Warning: variable 'Arity' is unused ./checker.erl:73: Warning: variable 'T' is unused ./checker.erl:84: Warning: variable 'T' is unused ./checker.erl:97: Warning: variable 'A' is unused erlc -W name_server1.erl erlc -W test_mnesia.erl erlc -W tracer_test.erl cd socket_dist; make compile cd: 1: can't cd to socket_dist make[1]: Entering directory `/home/drc/erlang/code' cd socket_dist; make compile
The error message starts looping, make is apparently unable to enter the socket_dist directory, so I ctrl-c out.
The directory does exist, and permissions look ok:
drc@dawn:~/erlang/code$ ls -dl so* drwxr-xr-x 2 drc drc 4096 2007-08-08 18:37 socket_dist/ -rw-r--r-- 1 drc drc 2664 2007-08-08 18:37 socket_examples.beam -rw-r--r-- 1 drc drc 2608 2007-08-08 18:37 socket_examples.erl -rw-r--r-- 1 drc drc 535 2007-08-08 18:37 sort.csv
I don’t know squat about make, but looking inside ./Makefile, these lines catch my eye:
compile: ${MODS:%=%.beam} subdirs trigramsOS.tab
@echo "make clean - clean up"
shoutcast: compile
erl -s shout start
subdirs:
cd socket_dist; make compile
cd escript-4.1; make
My first idea is to fully qualify socket_dist and escript-4.1. My guess is that should not be necessary, but what have I got to lose? I change the Makefile to read
subdirs:
cd /home/drc/erlang/code/socket_dist; make compile
cd /home/drc/erlang/code/escript-4.1; make
and then run make again.
drc@dawn:~/erlang/code$ make cd /home/drc/erlang/code/socket_dist; make compile make[1]: Entering directory `/home/drc/erlang/code/socket_dist' mkdir -p /home/drc/.erlang_config/ cp conf /home/drc/.erlang_config/lib_chan.conf make clean - clean up make[1]: Leaving directory `/home/drc/erlang/code/socket_dist' cd /home/drc/erlang/code/escript-4.1; make make[1]: Entering directory `/home/drc/erlang/code/escript-4.1' make[1]: Nothing to be done for `all'. make[1]: Leaving directory `/home/drc/erlang/code/escript-4.1' make clean - clean up
Well, that looks plausible, but I don’t understand why I had to edit the Makefile, and am not at all comfortable that this is going to work. I press on.
drc@dawn:~/erlang/code$ cd socket_dist/
drc@dawn:~/erlang/code/socket_dist$ make
mkdir -p /home/drc/.erlang_config/
cp conf /home/drc/.erlang_config/lib_chan.conf
make clean - clean up
To run the chat test program
1) start two xterms
2) in xterm one type -- make chat_server
3) in xterm two type -- make chat_client
Note: remember to type make in the directory above this
before running make in this directory
To run the lib_chan test program
1) start two xterms
2) in xterm one type -- make server
3) in xterm two type -- make client
OK, I’ll try it. I want to run lib_chan, so I open another console. In the first console I run make server:
drc@dawn:~/erlang/code/socket_dist$ make server
mkdir -p /home/drc/.erlang_config/
cp conf /home/drc/.erlang_config/lib_chan.conf
make clean - clean up
erl -pa ../ -boot start_clean -pa '.' -s lib_chan_test start_server
Erlang (BEAM) emulator version 5.5.2 [source] [async-threads:0] [kernel-poll:false]
lib_chan starting:"/home/drc/.erlang_config/lib_chan.conf"
ConfigData=[{port,1234},
{service,nameServer,
password,
"ABXy45",
mfa,
mod_name_server,
start_me_up,
notUsed},
{service,srpc,password,"secret",mfa,mod_srpc,start,[test1]},
{service,root,
password,
"verySecret",
mfa,
mod_srpc,
start,
[any_apply]},
{service,test1,password,"test1",mfa,mod_test1,start,{hi,joe}},
{service,echo,password,"echo1",mfa,mod_echo,start,{server,args}},
{service,math,password,"qwerty",mfa,mod_math,run,[]}]
That all looks in line with what the book leads me to expect. Now to run make client:
drc@dawn:~/erlang/code/socket_dist$ make client
mkdir -p /home/drc/.erlang_config/
cp conf /home/drc/.erlang_config/lib_chan.conf
make clean - clean up
erl -pa ../ -boot start_clean -pa '.' -s lib_chan_test start_client
Erlang (BEAM) emulator version 5.5.2 [source] [async-threads:0] [kernel-poll:false]
test:1
Eshell V5.5.2 (abort with ^G)
1> received:"hello"
test:2
received:{chan,<0.37.0>,15511210043330985984000000}
test:3
E=:{error,badService}
test:4
E = {error,authFail}
test:5
F=2432902008176640000
test:6
F={'EXIT',{modNotAllowed,test2}}
test:7
F1=2432902008176640000
test:8
The two error msgs don’t inspire confidence. At this point, I have nothing. My results on OS X are pretty much identical. I had a passing thought that maybe some port was blocked, so I turned off the firewall (I am behind a NAT router, so it’s ok). It didn’t help. I posted to erlang-questions, but I often experience a day or two lag between the time I post and the time I see my question appear. Tick tock.

Posts
1) The program is completely correct and working correctly.
Some of the test cases are *supposed* to write error messages - which they
do. I just re-ran the tests with identical results. So you system is working
fine.
In hind sight I guess it might have been better if the output was
test1: passed … etc.
I guess the fault is that I didn’t explain this.
I’ll fix this in the next release
if you look in lib_chan_test.erl test4 is coded as
test(4) ->
E = connect(”localhost”, 1234, math, “badSecret”, “”),
io:format(”E = ~p~n”,[E]);
The badsecret might have tipped you off
The result is {error, authFail} as required
2) For some reason your mail didn’t make it to the erlang mailing list
which is why nobody there responded
Cheers
/Joe Armstrong
August 17, 2007 @ 11:14 pm
Joe,
I have no idea how you happened across this place, but thanks for your help. I had briefly toyed with the idea of asking you for help, but I didn’t want to bug you until I had exhausted other options. On that note, I think I have figured out why my post to erlang-questions failed to show up. I’ll see if I’m right next time I have occasion to post.
I think it says a lot about your dedication to Erlang and its growing community that you would take time to answer a newb’s questions on an obscure blog. I really appreciate it.
Thanks again
David
August 18, 2007 @ 12:17 pm
About your directory troubles, you might have to unset CDPATH. I have never taken the time to figure out why, but make and CDPATH don’t go well together (it’s like make/shell forgets to look in the current directory when it has a CDPATH.
June 2, 2008 @ 9:02 am