chentc

2011年5月19日 #

socket描述符

摘要: 一开始调用socket,要求定义socket类型,Internet协议族(PF_INET)和数据报socket(SOCK_DGRAM)组成一个UDP协议socket。socket函数返回值是一个描述符,它具有其他Unix描述符的所有特性:可以用这个描述符调用read和write;可以用dup复制它,在调用fork之后,父进程和子进程可以共享它,可以调用fcntl来改变它的属性,可以调用colse来关闭它,等等。在我们的例子中可以看到socket描述符是函数sendto和recvfrom的第一个参数。当程序终止时(偶那个过调用exit),所有打开的描述符,包括socket描述符都会被内核关闭。我 阅读全文

posted @ 2011-05-19 10:51 chentc 阅读(3508) 评论(0) 推荐(0) 编辑

通过一个C应用程序分析BSD应用的特点

摘要: /* Send a UDP datagram to the daytime server on some host, read the reply,and print the time and date on the server.*/#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <stdio.h>#include <stdlib.h>#include <string 阅读全文

posted @ 2011-05-19 08:51 chentc 阅读(329) 评论(0) 推荐(0) 编辑

导航