PR_NewTCPSocket 编辑

Creates a new IPv4 TCP socket.

Syntax

#include <prio.h>

/wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRFileDesc* PR_NewTCPSocket(void);

Returns

The function returns one of the following values:

Description

TCP (Transmission Control Protocol) is a connection-oriented, reliable byte-stream protocol of the TCP/IP protocol suite. PR_NewTCPSocket creates a new IPv4 TCP socket. 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.

See Also

PR_NewTCPSocket is deprecated because it is hardcoded to create an IPv4 TCP socket. New code should use /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_OpenTCPSocket instead, which allows the address family (IPv4 or IPv6) of the new TCP socket to be specified.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:109 次

字数:5209

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文