套接字编程 - TCP / IP [英] Socket Programming - TCP/IP

查看:98
本文介绍了套接字编程 - TCP / IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我创建了套接字应用程序,其中服务器向客户端发送1024字节数据,客户端一次只能读取256个字节。 />


这里我丢失了一些数据,



我怎样才能确保我应该收到1024个字节。



问候,

Ranjith

Hi,

I have created socket application in which server is sending 1024 bytes data to client and client is able to read only 256 bytes at once.

here i am loosing some data ,

How can i make sure that i should receive 1024 bytes.

Regards,
Ranjith

推荐答案

你很可能期望所有数据出现在单个接收操作中。这不是TCP / IP的工作原理,它不像从磁盘读取数据块。 TCP / IP必须将您的数据块分解为更小的组件,这意味着并非所有数据都会同时被接收。您需要重复接收操作,直到缓冲区中有完整的1024个字节。谷歌的socket sample C ++,你会得到一些样本,展示它是如何完成的。
It is more than likely that you are expecting all the data to appear in a single receive operation. That is not how TCP/IP works, it is not like reading a block of data from disk. TCP/IP has to break your block of data down into smaller components, which means that not all the data will be received at the same time. You need to repeat the receive operation until you have the complete 1024 bytes in your buffer. Google for "socket sample C++" and you will get some samples that show how it is done.


这篇关于套接字编程 - TCP / IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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