send()和recv()通过TCP套接字 [英] send() and recv() through a TCP socket

查看:381
本文介绍了send()和recv()通过TCP套接字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法读取html文件有什么建议吗?

cant read the html file is there any suggestions ?

展开 | 选择 | Wrap | 行号

推荐答案

你调用send的方式是错误的,传递它的文件指针不起作用。您将需要从文件中读取数据(fread),然后使用send将其写入套接字。


此外,您假设send将发送您请求它发送的所有数据但发送不保证,它保证发送至少1个字节。


我建议你阅读 Beej的网络编程指南
The way you are calling send is just wrong, passing it the file pointer is not going to work. You will need to read data from the file (fread) and then write it to the socket using send.

Also you are assuming that send will send all the data that you request it sends but send does not guarantee that, it guarantees to send at least 1 byte.

I suggest you read Beej''s Guide to Network Programming


所以我必须把它放在一个循环中?

so i have to put it in a loop?

展开 | 选择 < span class =codeDivider> | Wrap | 行号


从第19行开始,代码没有意义,你甚至没有管理过(尝试过?)在fwrite,recv和send的函数调用中的正确位置获取正确类型的变量,你完全不清楚为什么你认为你需要调用fwrite。


试试Beej的网络编程指南第6节中给出的例子,编译它们使工作和理解它们如何/为什么工作。
From line 19 onwards that code makes no sense, you have not even managed (attempted?) to get the right types of variable in the right places in the function calls for fwrite, recv and send and it is not at all clear why you think you need to call fwrite.

Try the examples given in section 6 of Beej''s Guide to Network Programming, compile them make the work and understand how/why they work.


这篇关于send()和recv()通过TCP套接字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆