sendto()
来源:互联网 发布:winhexu盘数据恢复教程 编辑:程序博客网 时间:2024/06/11 16:22
sendto
The sendto function sends data to a specific destination.
int sendto( SOCKET s, const char* buf, int len, int flags, const struct sockaddr* to, int tolen);
Parameters
- s
- [in] Descriptor identifying a (possibly connected) socket.
- buf
- [in] Buffer containing the data to be transmitted.
- len
- [in] Length of the data in buf, in bytes.
- flags
- [in] Indicator specifying the way in which the call is made.
- to
- [in] Optional pointer to a sockaddr structure that contains the address of the target socket.
- tolen
- [in] Size of the address in to, in bytes.
Return Values
If no error occurs, sendto returns the total number of bytes sent, which can be less than the number indicated by len. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError.
Remarks
The sendto function is used to write outgoing data on a socket. For message-oriented sockets, care must be taken not to exceed the maximum packet size of the underlying subnets, which can be obtained by using getsockopt to retrieve the value of socket option SO_MAX_MSG_SIZE. If the data is too long to pass atomically through the underlying protocol, the error WSAEMSGSIZE is returned and no data is transmitted.
The to parameter can be any valid address in the socket's address family, including a broadcast or any multicast address. To send to a broadcast address, an application must have used setsockopt with SO_BROADCAST enabled. Otherwise, sendto will fail with the error code WSAEACCES. For TCP/IP, an application can send to any multicast address (without becoming a group member).
Note If a socket is opened, a setsockopt call is made, and then a sendto call is made, Windows Sockets performs an implicit bind function call.
If the socket is unbound, unique values are assigned to the local association by the system, and the socket is then marked as bound. An application can use getsockname to determine the local socket name in this case.
The successful completion of a sendto does not indicate that the data was successfully delivered.
The sendto function is normally used on a connectionless socket to send a datagram to a specific peer socket identified by the to parameter. Even if the connectionless socket has been previously connected to a specific address, the to parameter overrides the destination address for that particular datagram only. On a connection-oriented socket, the to and tolen parameters are ignored, making sendto equivalent to send.
For Sockets Using IP (Version 4)
To send a broadcast (on a SOCK_DGRAM only), the address in the to parameter should be constructed using the special IP address INADDR_BROADCAST (defined in Winsock2.h), together with the intended port number. It is generally inadvisable for a broadcast datagram to exceed the size at which fragmentation can occur, which implies that the data portion of the datagram (excluding headers) should not exceed 512 bytes.
If no buffer space is available within the transport system to hold the data to be transmitted, sendto will block unless the socket has been placed in a nonblocking mode. On nonblocking, stream oriented sockets, the number of bytes written can be between 1 and the requested length, depending on buffer availability on both the client and server systems. The select, WSAAsyncSelect or WSAEventSelect function can be used to determine when it is possible to send more data.
Calling sendto with a len of zero is permissible and will return zero as a valid value. For message-oriented sockets, a zero-length transport datagram is sent.
The flags parameter can be used to influence the behavior of the function invocation beyond the options specified for the associated socket. The semantics of this function are determined by the socket options and the flags parameter. The latter is constructed by using the bitwise OR operator with any of the following values.
- sendto()
- sendTo
- sendto()函数
- 郁闷的sendto失败
- send/sendto/sendmsg
- send,recv,sendto,recvfrom
- recvfrom/sendto的效率
- send,recv,sendto,recvfrom
- send,recv,sendto,recvfrom
- win7 Sendto 文件夹路径
- 关于sendto : Permission denied
- send,recv,sendto,recvfrom
- send,recv,sendto,recvfrom
- send,recv,sendto,recvfrom
- send,recv,sendto,recvfrom
- sendto()_Linux C函数
- sendto 和WSASendTo
- send,recv,sendto,recvfrom
- 设计模式(七)[模板方法(Template Method)模式]
- Linux用户管理
- 章节分割器 v2.0 Beta0618 版
- 因为不知道,所以不知道
- 用电脑的健康问题
- sendto()
- 从SQL SERVER中提取出除newid()之外全重复的行算法
- Delphi 字符串中末位是双字节字符的处理(避免最后一位为乱码)
- 有用代码
- (转)ssh学习笔记
- 对话框
- 常用算法设计方法
- 开篇
- IBM DB2 日常维护汇总