2

Currently i'm having the problem, that if I send a buffer, it may be send only partially and return the count of bytes sent. Is there any way to set some option or sth. that prevents the bsd socket from sending partially?

4

1 回答 1

2

SOCK_STREAM通常,对于TCP 等套接字类型,没有办法做到这一点。SOCK_DATAGRAM(对于 IP,这意味着 UDP)和SOCK_SEQPACKET(对于 IP,没有这样的东西)会做你想做的事,但它们自己有不同的限制。

无论如何,解决方案是您需要自己进行数据缓冲和成帧。也就是说,您需要在发送的流中包含带内信息,以允许接收者重建您想要的“数据包”边界。

于 2013-09-28T21:18:42.597 回答