您的位置:首页 > 理论基础 > 计算机网络

运行unix网络编程的的第一个例子

2012-07-06 20:09 411 查看
本文章使转载于博客:http://blog.csdn.net/zxremail/article/details/4858714为了以后自己查阅方便所以贴在本文中.

运行书本中的程序。
1,首先,进入到Stevens的主页中下载原码
2,然后,编译程序,方法如下:

    tar -zxvf  unpv12e.tar.gz (-C dir)//解压文件

    cd unpv12e
    ./configure    # try to figure out all implementation differences

    cd lib         # build the basic library that all programs need
    make           # use "gmake" everywhere on BSD/OS systems

    cd ../libfree  # continue building the basic library
    make

    cd ../libgai   # the getaddrinfo() and getnameinfo() functions
    make

    cd ../libroute # only if your system supports 4.4BSD style routing sockets
    make           # only if your system supports 4.4BSD style routing sockets

    cd ../libxti   # only if your system supports XTI
    make           # only if your system supports XTI

    cd ../intro    # build and test a basic client program
    make daytimetcpsrv

    make daytimetcpcli

此时会生成 daytimetcpsrv daytimetcpsrv.o daytimetcpcli daytimetcpcli.o

3、linux现在因为安全问题,各个发行版本默认是不开daytime服务的。  
   
  第一个例子实际上是两个程序,客户端和服务端,你很有可能只运行了客户端,没有运行服务端程序。  
   
  服务端程序在书上第12页……你不会尚还没有看到那里吧?  
   
  PS:由于要打开端口,所以服务端程序需要用root权限执行,所以你可以先   

    sudo   ./daytimetcpsrv  (如果本身就是root就不需要sudo)

  然后再开一个终端运行   ./daytimetcpcli 127.0.0.1  就可以看到返回的时间了.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息