G9677607 @ Blog *+﹏+*~ Blog @ G9677607

2008年6月9日 星期一

2008年6月2日 星期一

網路socket編程指南

網路socket編程指南
出處:http://member.netease.com/~chcd/socket.htm

譯者:網前沖
[Version 1.5.5]
[ http://www.ecst.csuchico.edu/~beej/guide/net/

________________________________________
目錄:
1)
什麼是套接字?
2) Internet
套接字的兩種類型
3)
網路理論
4)
結構體
5)
本機轉換
6) IP
位址和如何處理它們
7) socket()
函數
8) bind()
函數
9) connect()
函數
10) listen()
函數
11) accept()
函數
12) send()
recv()函數
13) sendto()
recvfrom()函數
14) close()
shutdown()函數
15) getpeername()
函數
16) gethostname()
函數
17)
功能變數名稱服務(DNS
18)
客戶-伺服器背景知識
19)
簡單的伺服器
20)
簡單的用戶端
21)
數據報套接字Socket
22)
阻塞
23) select()--
多路同步I/O
24)
參考資料
link:

sendto 和 recvfrom

sendto 和 recvfrom 系統呼叫可用來收發非連線導向的網路資料。

使用例:

#include
#include

int sd; /* socket descriptor */
int count; /* number of bytes transmitted */
char buf[100]; /* transmission buffer */
int len; /* max number of bytes transmitted */

int flags; /* for handling special messages */
struct sockaddr_in to, from; /* endpoint addresses */
int addrlen; /* length of address structure */
count = sendto( sd, buf, len, flags, (struct sockaddr*) &to, addrlen );
count = recvfrom( sd, buf, len, flags, (struct sockaddr*) &from, &addrlen );