erlang手记(2)

1> c(server_1).
{ok,server_1}
2>
2> Myserver=server_1:start(".").
<0.40.0>
3>
3> client_1:get_file(Myserver,"test").
{ok,<<"afdsaf\nadfasdfsad\n124234\nierweriwer\n">>}
4> client_1:list_dir(Myserver,"/").
{ok,["sys","selinux","tmp",".autofsck","root","opt","sbin",
     "media",".pulse","var","dev","srv","home","bin","misc",
     "mnt",".dbus","lib","etc","lost+found","proc","net",
     ".pulse-cookie","usr","boot"]}
5> c(client_1).
{ok,client_1}
6> client_1:list_dir(Myserver,"/usr").
{ok,["tmp","sbin","src","local","share","bin","libexec",
     "lib","etc","games","java","include"]}
7>
7> client_1:ls(Myserver).
{ok,["client_1.beam","server_1.beam","1","server_1.erl",
     "client_1.erl","erl_crash.dump","test",".1_server.erl.swp"]}
8> halt().




server_1.erl

[deep@deep erlangstudy]$ cat server_1.erl
-module(server_1).
-export([start/1,loop/1]).
start(Dir)->spawn(server_1,loop,[Dir]).
loop(Dir)->
   receive
      {Client,list_dir}->
           Client!{self(),file:list_dir(Dir)};
      {Client,{list_dir,Mydir}}->
           Client!{self(),file:list_dir(Mydir)};
      {Client,{get_file,File}}->
           Fullname=filename:join(Dir,File),
           Client!{self(),file:read_file(Fullname)}
   end,
loop(Dir).

 

http://www.qiyeku.com/xinwen7355834.html
http://www.qiyeku.com/xinwen7355832.html
http://www.qiyeku.com/xinwen7355830.html
http://www.qiyeku.com/xinwen7355828.html
http://www.qiyeku.com/xinwen7355826.html
http://www.qiyeku.com/xinwen7355824.html
http://www.qiyeku.com/xinwen7355821.html
http://www.qiyeku.com/xinwen7355819.html
http://www.qiyeku.com/xinwen7355817.html
http://www.qiyeku.com/xinwen7355788.html
http://www.qiyeku.com/xinwen7355724.html
http://www.qiyeku.com/xinwen7355694.html
http://www.qiyeku.com/xinwen7355689.html
http://www.qiyeku.com/xinwen7355682.html
http://www.qiyeku.com/xinwen7355675.html
http://www.qiyeku.com/xinwen7355670.html
http://www.qiyeku.com/xinwen7355660.html
http://www.qiyeku.com/xinwen7355654.html
http://www.qiyeku.com/xinwen7355651.html
http://www.qiyeku.com/xinwen7355647.html
http://www.qiyeku.com/xinwen7355645.html
http://www.qiyeku.com/xinwen7355642.html
http://www.qiyeku.com/xinwen7355639.html
http://www.qiyeku.com/xinwen7355635.html
http://www.qiyeku.com/xinwen7355580.html
http://www.qiyeku.com/xinwen7355576.html
http://www.qiyeku.com/xinwen7355552.html
http://www.qiyeku.com/xinwen7355534.html
http://www.qiyeku.com/xinwen7355526.html
http://www.qiyeku.com/xinwen7355475.html

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值