PR_OpenTCPSocket 编辑
Creates a new TCP socket of the specified address family.
Syntax
#include <prio.h> /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRFileDesc* PR_OpenTCPSocket(PRIntn af);
Parameters
The function has the following parameters:
af
- The address family of the new TCP socket. Can be
PR_AF_INET
(IPv4),PR_AF_INET6
(IPv6), orPR_AF_LOCAL
(Unix domain, supported on POSIX systems only).
Returns
The function returns one of the following values:
- Upon successful completion, a pointer to the
/wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRFileDesc
object created for the newly opened TCP socket. - If the creation of a new TCP socket failed,
NULL
.
Description
TCP (Transmission Control Protocol) is a connection-oriented, reliable byte-stream protocol of the TCP/IP protocol suite. PR_OpenTCPSocket
creates a new TCP socket of the address family af
. A TCP connection is established by a passive socket (the server) accepting a connection setup request from an active socket (the client). Typically, the server binds its socket to a well-known port with /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_Bind
, calls /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_Listen
to start listening for connection setup requests, and calls /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_Accept
to accept a connection. The client makes a connection request using /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_Connect
.
After a connection is established, the client and server may send and receive data between each other. To receive data, one can call /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_Read
or /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_Recv
. To send data, one can call /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_Write
, /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_Writev
, /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_Send
, or /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_TransmitFile
. /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_AcceptRead
is suitable for use by the server to accept a new client connection and read the client's first request in one function call.
A TCP connection can be shut down by /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_Shutdown
, and the sockets should be closed by /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_Close
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论