sClient=socket(AF_INET,SOCK_STREAM,0)意思是什么
2个回答
展开全部
生成一个TCP的socket
Function: int socket (int namespace, int style, int protocol)
This function creates a socket and specifies communication style style, which should be one of the socket styles listed in 16.2 Communication Styles. The namespace argument specifies the namespace; it must be PF_LOCAL (see section 16.5 The Local Namespace) or PF_INET (see section 16.6 The Internet Namespace). protocol designates the specific protocol (see section 16.1 Socket Concepts); zero is usually right for protocol.
The return value from socket is the file descriptor for the new socket, or -1 in case of error. The following errno error conditions are defined for this function:
EPROTONOSUPPORT
The protocol or style is not supported by the namespace specified.
EMFILE
The process already has too many file descriptors open.
ENFILE
The system already has too many file descriptors open.
EACCES
The process does not have the privilege to create a socket of the specified style or protocol.
ENOBUFS
The system ran out of internal buffer space.
The file descriptor returned by the socket function supports both read and write operations. However, like pipes, sockets do not support file positioning operations.
SOCK_STREAM提供面向连接的稳定数据传输,即TCP协议。SOCK_STREAM应用在C语言socket编程中,在进行网络连接前,需要用socket函数向系统申请一个通信端口。socket函数的使用方法如下:
int socket(int domain, int type, int protocol);
在参数表中,domain指定使用何种的地址类型,比较常用的有:
PF_INET, AF_INET: Ipv4网络协议;
PF_INET6, AF_INET6: Ipv6网络协议。
type参数的作用是设置通信的协议类型,可能的取值如下所示:
SOCK_STREAM: 提供面向连接的稳定数据传输,即TCP协议。
OOB: 在所有数据传送前必须使用connect()来建立连接状态。
SOCK_DGRAM: 使用不连续不可靠的数据包连接。
SOCK_SEQPACKET: 提供连续可靠的数据包连接。
SOCK_RAW: 提供原始网络协议存取。
SOCK_RDM: 提供可靠的数据包连接。
SOCK_PACKET: 与网络驱动程序直接通信。
参数protocol用来指定socket所使用的传输协议编号。这一参数通常不具体设置,一般设置为0即可。
Function: int socket (int namespace, int style, int protocol)
This function creates a socket and specifies communication style style, which should be one of the socket styles listed in 16.2 Communication Styles. The namespace argument specifies the namespace; it must be PF_LOCAL (see section 16.5 The Local Namespace) or PF_INET (see section 16.6 The Internet Namespace). protocol designates the specific protocol (see section 16.1 Socket Concepts); zero is usually right for protocol.
The return value from socket is the file descriptor for the new socket, or -1 in case of error. The following errno error conditions are defined for this function:
EPROTONOSUPPORT
The protocol or style is not supported by the namespace specified.
EMFILE
The process already has too many file descriptors open.
ENFILE
The system already has too many file descriptors open.
EACCES
The process does not have the privilege to create a socket of the specified style or protocol.
ENOBUFS
The system ran out of internal buffer space.
The file descriptor returned by the socket function supports both read and write operations. However, like pipes, sockets do not support file positioning operations.
SOCK_STREAM提供面向连接的稳定数据传输,即TCP协议。SOCK_STREAM应用在C语言socket编程中,在进行网络连接前,需要用socket函数向系统申请一个通信端口。socket函数的使用方法如下:
int socket(int domain, int type, int protocol);
在参数表中,domain指定使用何种的地址类型,比较常用的有:
PF_INET, AF_INET: Ipv4网络协议;
PF_INET6, AF_INET6: Ipv6网络协议。
type参数的作用是设置通信的协议类型,可能的取值如下所示:
SOCK_STREAM: 提供面向连接的稳定数据传输,即TCP协议。
OOB: 在所有数据传送前必须使用connect()来建立连接状态。
SOCK_DGRAM: 使用不连续不可靠的数据包连接。
SOCK_SEQPACKET: 提供连续可靠的数据包连接。
SOCK_RAW: 提供原始网络协议存取。
SOCK_RDM: 提供可靠的数据包连接。
SOCK_PACKET: 与网络驱动程序直接通信。
参数protocol用来指定socket所使用的传输协议编号。这一参数通常不具体设置,一般设置为0即可。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询