几个基本函数的解释:
fd_set Structure:
The fd_set structure is used by various Windows Sockets
functions and service providers, such as the select function, to place sockets into a "set"
for various purposes, such as testing a given socket for readability using the
readfds parameter of the select function.
fd_set结构简单的来说就是用来存储各种不同类型的Windows Socket的一个数据结构。
原型是:
typedef struct fd_set {
u_int fd_count;
SOCKET fd_array[FD_SETSIZE];
} fd_set;
select Function:
The select function determines the status of one ore more sockets,waiting if necessary, to perform synchronous I/O.
select 函数用来判断一个或更多个socket的状态,来决定是否有必要来执行同步I/O操作。
函数原型是:
int select(
__in int nfds,
__in_out fd_set* readfds,
__in_out fd_set* writefds,
__in_out fd_set* exceptfds,
__in const struct timeval* timeout
);
Return Value:
The select function returns the total number of socket handles that are ready and contained in the fd_set structures, zero if the time limit expired, or SOCKET_ERROR if an error occurred. If the return value is SOCKET_ERROR, WSAGetLastError can be used to retrive a specific error code.
Remarks
The select function is used to determine the status of one or more
sockets. For each socket, the caller can request information on read, write, or
error status. The set of sockets for which a given status is requested is
indicated by an fd_set structure. The sockets
contained within the fd_set structures must be associated with a single
service provider. For the purpose of this restriction, sockets are considered to
be from the same service provider if the WSAPROTOCOL_INFO structures describing
their protocols have the same providerId value. Upon return, the
structures are updated to reflect the subset of these sockets that meet the
specified condition. The select function returns the number of sockets
meeting the conditions. A set of macros is provided for manipulating an
fd_set structure. These macros are compatible with those used in the
Berkeley software, but the underlying representation is completely
different.
The parameter readfds identifies the sockets that are to be checked
for readability. If the socket is currently in the listen state, it will be marked as readable if an
incoming connection request has been received such that an accept is guaranteed to complete without
blocking. For other sockets, readability means that queued data is available for
reading such that a call to recv, WSARecv, WSARecvFrom, or recvfrom is guaranteed not to block.
For connection-oriented sockets, readability can also indicate that a request
to close the socket has been received from the peer. If the virtual circuit was
closed gracefully, and all data was received, then a recv will return
immediately with zero bytes read. If the virtual circuit was reset, then a
recv will complete immediately with an error code such as WSAECONNRESET.
The presence of OOB data will be checked if the socket option SO_OOBINLINE has
been enabled (see setsockopt).
The parameter writefds identifies the sockets that are to be checked
for writability. If a socket is processing a connect call (nonblocking), a socket is
writeable if the connection establishment successfully completes. If the socket
is not processing a connect call, writability means a send, sendto, or
WSASendto are guaranteed to succeed.
However, they can block on a blocking socket if the len parameter exceeds
the amount of outgoing system buffer space available. It is not specified how
long these guarantees can be assumed to be valid, particularly in a
multithreaded environment.
The parameter exceptfds identifies the sockets that are to be checked
for the presence of OOB data or any exceptional error conditions.
Note Out-of-band data will only be reported in this way if
the option SO_OOBINLINE is FALSE. If a socket is processing a connect
call (nonblocking), failure of the connect attempt is indicated in
exceptfds (application must then call getsockopt SO_ERROR to determine the error
value to describe why the failure occurred). This document does not define which
other errors will be included.
Any two of the parameters, readfds, writefds, or
exceptfds, can be given as null. At least one must be non-null, and any
non-null descriptor set must contain at least one handle to a socket.
timeval Structure:
The timeval structure is used to specify time values. It is
associated with the Berkeley Software Distribution (BSD) Time.h header
file.
typedef struct timeval {
long tv_sec;
long tv_usec;
} timeval;
这个也比较常用,第一个类型tv_sec秒值,第二个usec毫秒值。
Send Function :
The send
function sends data on a connected socket.
int send(
__in SOCKET s,
__in const char* buf,
__in int len,
__in int flags
);
Return Value
If no error occurs, send returns the total number of bytes sent, which can
be less than the number requested to be sent in the len parameter.
Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be
retrieved by calling WSAGetLastError.
如果没有错误发生,就返回被传递的总字节数。
分享到:
相关推荐
Socket网络编程-文件上传Socket网络编程-文件上传Socket网络编程-文件上传Socket网络编程-文件上传Socket网络编程-文件上传Socket网络编程-文件上传Socket网络编程-文件上传Socket网络编程-文件上传Socket网络编程-...
在IT领域,网络编程是构建分布式系统和网络应用程序的基础,而Windows平台上的网络编程往往涉及到Win32 API和套接字(socket)技术。Visual Studio 2008是一款广泛使用的开发工具,它支持多种编程语言,包括C++,...
标题“win-socket-demo_socket编程_socket_windows_DEMO_”指的是一个Windows平台上的Socket编程示例项目,主要涉及网络通信的基础知识,尤其是如何在Windows环境下使用Socket API进行客户端和服务器端的交互。...
在本文中,我们将深入探讨如何在Win32平台上利用C++和Socket技术构建一个C/S架构的聊天应用程序,实现客户端间的群聊和私聊功能。首先,我们需要了解几个关键概念和关键技术。 1. **Win32 API**:Windows操作系统...
这个资源主要涵盖了华中科技大学计算机通信与网络课程中的Socket编程部分,它包括了学习资料、源代码示例以及相关说明文档。Socket编程是网络编程的核心技术,主要用于实现不同计算机之间的通信,通过创建套接字接口...
HP-Socket 提供了大量的 Demo 示例如:PUSH 模型示例、PULL 模型示例、PACK 模型示例、性能测试示例以及其它编程语言示例,以便让使用者能方便快速地学习和使用 HP-Socket。 HP-Socket 的特点 * 高性能:HP-Socket...
Java 多线程-Socket 编程 Java 多线程-Socket 编程是指在 Java 语言中使用多线程技术来实现网络编程,特别是使用 Socket 编程来实现客户端和服务器端的通信。在 Java 中,多线程可以使用 Thread 类和 Runnable 接口...
【Linux网络编程-网络基础-socket编程-高并发服务器】 在深入探讨Linux下的网络编程之前,我们首先要理解网络通信的基础概念——协议。协议是数据传输和解释的规则,它确保了不同设备之间的通信能顺利进行。例如,...
Socket调试工具socket-1.0-win32-chs.zip是一个专为Windows 32位操作系统设计的TCP/IP套接字调试软件。这个压缩包包含了该工具的中文版本,方便国内用户使用。在IT行业中,特别是在网络编程领域,理解和熟练使用...
Lua Socket是Lua编程语言的一个扩展库,专门用于网络通信,它提供了一套完整的TCP、UDP以及伪套接字(如管道和文件描述符)接口,让Lua程序员能够轻松地进行Socket编程。在本文中,我们将深入探讨Lua Socket的使用、...
**Win32 Socket API网络编程入门演示程序** 在IT领域,网络编程是构建分布式系统、实现客户端-服务器通信的关键技术。对于Windows操作系统,Win32 Socket API(也称为Winsock)是开发网络应用程序的主要接口。这个...
01_Linux网络编程-网络基础-socket编程-高并发服务器
在Windows操作系统环境下,使用Win32 API进行SOCKET通信是一种常见的网络编程方式。本项目提供了一个简单的基于Win32控制台的SOCKET通信实例,它展示了如何创建客户端和服务端进行双向数据交换的基础步骤。下面将...
网络socket编程集锦,程序经过Linux平台PC上用 GNU 的gcc 成功编译过,适合新手学习借鉴。
"hp-socket-dev"是一个与HP(Hewlett-Packard)相关的网络库资源,主要涉及的是Socket编程。在IT行业中,Socket编程是网络通信的基础,它允许不同计算机间的进程通过网络进行通信。在这个资源包中,我们可以期待找到...
这个版本号228意味着它是PyWin32的第228次更新,通常会包含错误修复和新功能。 安装PyWin32时,需要注意以下几点: 1. **平台兼容性**:确保你的操作系统是64位Windows,并且你的Python环境也是64位的。如果使用32...
Socket编程之聊天程序 - 模拟Fins/ModBus协议通信过程 TcpChatter - Blog项目源代码(OpenSource) ----------------------------------------- 设备控制软件编程涉及到的基本通信方式主要有TCP/IP与串口,用到的...
这个Win32 Socket聊天程序提供了一个学习网络编程和C++实践的实例,有助于深入理解网络通信的基础概念和实现细节。通过分析和修改这个项目,开发者可以提升自己的网络编程技能,并了解如何构建实际的网络应用。
标题中的“易语言版HP-Socket+源码+示例”指的是使用易语言开发的HP-Socket组件的源代码及相关的示例程序。易语言是一种中国本土化编程语言,旨在降低编程难度,让不懂英文的用户也能进行软件开发。HP-Socket是一个...
在Linux系统中,Socket编程是实现网络通信的基础,它提供了进程间通过网络交换数据的接口。C++ Socket库是Linux下进行网络编程的常用工具,它允许开发者利用标准的C++语言来创建复杂的网络应用程序。本资源“实战...