【发布时间】:2015-01-28 03:00:39
【问题描述】:
我在 MSDN 中阅读了有关 send() 和 recv() 函数的信息,但我不确定我是否理解一件事。
如果我发送一个大小为 256 的缓冲区,并接收前 5 个字节,那么下次我调用 recv() 函数时,它将指向第 6 个字节并从那里获取数据?
例如:
char buff[256];
memcpy(buff,"hello world",12);
send(sockfd, buffer, 100) //sending 100 bytes
//server side:
char buff[256];
recv(sockfd, buff, 5) // now buffer contains : "Hello"?
recv(socfd, buff,5) // now I ovveride the data and the buffer contains "World"?
谢谢!
【问题讨论】:
-
recv()不会改变你的缓冲区指向的位置。但它会告诉你它读取了多少,这样你就可以从它停止的地方继续。不过,您需要自己调整传递它的指针和大小。
标签: c sockets client-server server recv