##得到更多資料歡迎進入個人網站或者 csdn或者博客園html
今天在溫習計算機網絡時,忽然將我好久前買的《unix網絡編程第三版卷一》拿出來看看了。放了兩年了,哈哈。主要講的套接字,以前編寫android時用過socket(java),而本書全是c語言仍是能夠好好學習下的;然而第一個程序我就編譯錯誤了,什麼鬼!! ,還好以後,用了神奇的谷歌,發現源碼下竟然有readme。真是提醒我了,之後必定要注意這個文件。
java
#1.解壓文件進入主目錄 cd intro #2.直接編譯 gcc -o 1.out daytimetcpcli.c #錯誤提示以下: daytimetcpcli.c:1:17: fatal error: unp.h: No such file or directory #include "unp.h" ^ compilation terminated. #在../key目錄下找到unp.h。繼續提醒沒有<sys/fiflo.h>從網上下載繼續出問題。 #3.看到目錄下有make文件,make一下:顯示以下: peace@peace:~/workspace/unpv13e/unpv13e/intro$ make Makefile:1: ../Make.defines: No such file or directory make: *** No rule to make target '../Make.defines'. Stop.
崩潰,簡答的測試程序都不行。沒辦法,谷歌;終於找到了android
參照主目錄下readme文件執行一下命令:
注意:
1最後一個命令有改動
2前面三個命令是必須的 ./configure,cd lib ,make
3後面的cd ../libfree cd ../libroute cd ../libxti 知足條件才須要執行編程
./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 ../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 #官方是make daytimetcpcli
終於編譯成功了。內牛滿面;
測試:網絡
sudo ./daytimetcpcli 127.0.0.1 [sudo] password for peace: connect error: Connection refused 哭暈啊
到網上一查才發現是系統默認沒打開daytime服務。
解決辦法:
在intro中執行一下命令打開daytime服務socket
sudo ./daytimetcpsrv
因爲此程序在運行中;須要另外打開終端,進入intro中測試tcp
sudo ./daytimetcpcli 127.0.0.1 [sudo] password for peace: Thu Jul 23 21:50:23 2015
獲得正常結果;
個人失誤,但願能對你們有幫助;學習