sendto()

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.

ValueMeaning
MSG_DONTROUTESpecifies that the data should not be subject to routing. A Windows Sockets service provider can choose to ignore this flag.
MSG_OOBSends OOB data (stream-style socket such as SOCK_STREAM only). Also see DECnet Out-Of-band data for a discussion of this topic.

 
08-24
本软件是用批处理制作的实用小工具,安装后会给“发送到”增加一些实用的特性,如:复制文件路径名、批量重命名、快速打开目录、剪贴板文字保存到文件等等。功能的实现是由20多个批处理脚本完成的,批处理有很强的可定制性,你甚至可以自己添加批处理脚本进去。<br>●安装说明<br>  最初的版本只需将文件夹复制到当前用户 SendTo 目录下便可以使用全部功能了。当前版本中我制作了一个安装批处理,只需将文件解压到任意目录后执行 Install.cmd 按提示操作便可完成安装。批处理脚本中大量使用了 CMD 命令行的特性,所以不支持 9X 系列系统,2000 应该能用但我没做测试。软件安装过程会注册一个用户变量,位置在 HKEY_CURRENT_USER\\Environment 下 SendTo+ 键,必须注销或重启后用户变量才生效,安装完成后会提示注销一下系统。<br>●功能说明<br>  默认正常安装后会在当前用户 SendTo 目录下生成 SendTo+ 文件夹,使用方法是在任意目录选中文件或文件夹指向发送到、 SendTo+ 便会看到功能选项。注意选中文件和文件夹后的所调用的功能是不一样的,支持多选,只要是合乎情理的操作都支持多个文件或文件夹。目录列表及个人推荐度如下:<br> ○命令提示符 ★★★<br> ○打开目录 ★★★<br>  ◇添加此文件夹<br>  ◇移除此文件夹<br> ○快捷方式<br>  ◇添加到“开始菜单”<br>  ◇添加到“快速启动” ★★<br>  ◇添加到“其它文件夹” ★★★<br>  ◇添加到“收藏”<br> ○文本操作<br>  ◇复制文本文字到剪贴板<br>  ◇剪贴板文字到同名文本 ★★★<br>  ◇剪贴板文字生成新文本 ★★★★<br>  ◇剪贴板文字替换到文本<br>  ◇剪贴板文字追加到文本<br>  ◇清空文本文件<br> ○文件操作<br>  ◇复制文件路径到剪贴板<br>  ◇复制文件名到剪贴板 ★★★<br>  ◇复制文件完整路径到剪贴板 ★★★★<br>  ◇随机数字批量重命名 ★★★<br>  ◇文本标题批量重命名 ★★★<br>  ◇序号数字批量重命名<br>  ◇以当前日期新建文件夹<br>  ◇以同名或剪贴板新建文件夹 ★★★<br>  ◇撤销上次批量重命名<br>  ◇加密批处理文件<br><br>●进阶说明<br>  由于软件的使用很简单不做过多说明,说一下操作方式。部分的操作是区分当前选中的是文件还是文件夹的,如“命令提示符”项当选中文件时打开的命令窗口的路径是文件所在路径,而选中文件夹时为选中的文件夹路径。同样的还有“剪贴板文字生成新文本”项等,并且会以文本的第一行重新命名。最特特殊的是“以同名或剪贴板新建文件夹”选中文件会以相同名建立文件夹,选中文件夹会将剪贴板内容为名在其下建立文件夹,你可以尝试选中多个文件与文件夹看看有何效果。还有一些操作是无意义的,比如选中多个文件调用“以当前日期新建文件夹”只会生成一个文件夹,但选中多个文件夹会大不相同。还有一些操作是不区分文件和文件夹以及目录的,比如“撤销上次批量重命名”在那里操作结果是一样的。<br>  关于在“发送到”生成的文件夹的名字,可以自己修改 SendTo+.ini 中 = 号后的内容,使其更合乎自己的使用习惯。其文件夹下的操作项名可以修改 Install.cmd 中 “/f:” 后跟随的 *.lnk 的名字,可以增加序号以使按习惯的顺序排列。在 SendTo+ 下 CMD 文件夹下的 ShortcutToFolder.ini 是添加到“其它文件夹”的文件记录,以“*”号开头的行会被置顶选择,当执行操作后,所需目标文件夹不在此处时会提示输入目标位置,并记录在此文件中,后续版本中会增加根据使用频繁度调整顺序功能。关于隐藏属性的 Desktop.ini 是文件夹显示图标的定义文件,请不要删除。<br>  已知问题,当文件名含有 & | 等特殊字符时可能会操作失败,原因是发送到传递给脚本的参数默认是不加引号的会造成解析参数错误,对付的办法是更改文件名去掉特殊字符或在文件名中添加空格,除此没有彻底解决的办法。多文件操作时出现“Windows 无法访问指定设备、路径或文件。您可能没有合适的权限访问这个项目。”错误提示,是选择的文件太多,超过命令行的字符限制,解决的办法是减少文件的选择量。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值