请教:socket 编程中,send ,recv 的作用和 write , read 是一样的,是吗?谢谢!

NPSGSYS 2006-10-17 09:29:17
请教:
socket 编程中,send ,recv 的作用和 write , read 是一样的,是吗?
一般是使用 send ,recv 还是使用 write , read 呢?
谢谢!
...全文
315 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
vipzhouch 2006-10-17
  • 打赏
  • 举报
回复
send recv 是面向套接口id
read write 需要的是文件描述符
tcww88 2006-10-17
  • 打赏
  • 举报
回复
What is the difference between read() and recv()?
From Andrew Gierth (andrew@erlenstar.demon.co.uk):

read() is equivalent to recv() with a flags parameter of 0. Other values for the flags parameter change the behaviour of recv(). Similarly, write() is equivalent to send() with flags == 0.

It is unlikely that send()/recv() would be dropped; perhaps someone with a copy of the POSIX drafts for socket calls can check...

Portability note: non-unix systems may not allow read()/write() on sockets, but recv()/send() are usually ok. This is true on Windows and OS/2, for example.
jason69s 2006-10-17
  • 打赏
  • 举报
回复
read和write也可以对socket的fd进行处理

二者在BSD4.4上是一致的,最终会调到统一的内核处理函数,只是recv和send多些选项(flag),估计在linux上的主要功能也差不多吧

23,124

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧