Below you will find pages that utilize the taxonomy term “Socket”
June 16, 2011
c语言socket编程常用函数2
"\u003cp\u003e\u003cstrong\u003esocket()函数\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003e#include\n#include int socket(int domain, int type, int protocol);\ndomain应该设置为”AF_INET”,和上面数据结构 struct sockaddr_in 中一样,或者其它的type 告诉内容是SOCK_STREAM还是SOCK_DGRAM 类型,或者其它的.\nprotocol 设置为0.\u003c/p\u003e\n\u003cp\u003esocket()只是返回以后在系统调用中可能用到的socket描述符,或者错误的时候返回-1.全局变量errno中将存储返回的错误值.\u003c/p\u003e\n\u003cp\u003e=====================\n\u003cstrong\u003ebind() 函数\u003c/strong\u003e\n一旦你有一个套接字,你可能要将套接字和机器上的一定的端口关联起来。 ( 如果你想用 listen() 来侦听一定端口的数据,这是必要一步 –MUD 告 诉你说用命令 “telnet x.y.z 6969” 。 ) 如果你只想用 connect() ,那么这个步骤没有必 要 。\n但是无论如何,请继续读下去。\u003c/p\u003e\n\u003cp\u003e这里是系统调用 bind() 的大概:\u003c/p\u003e\n\u003cp\u003e#include\n#include int bind(int …\u003c/p\u003e"