通过套接字的最大数据 [英] Max data via sockets

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

问题描述

我设置了

sc.setSocketOption(sc.RCVBUF, 163840);


但只能接收16384.我一次可以接收的最大数量是吗?

实际的外观:
如果来自服务器的响应包含20000字节,则应用程序执行16384字节,而当我再次发送另一个或相同(无关紧要)的请求时,则应用程序执行下一个3616字节,这是第一次之后剩下的,这意味着数据存储在某处...


but can receive only 16384. Is it maximum what I can receive at once?

How it looks practically:
If response from server contains 20000 bytes, then application performs 16384 bytes, and when I send another or same(doesn''t matter) request again, then application performs next 3616 bytes, that was left after first time, it means, that this data were stored somewhere...

推荐答案

似乎您正在使用TCP协议.如果您使用的是TCP协议,则数据将存储在缓冲区中,直到您读取它为止,即,如果您接收到1000个字节,但您仅读取了400个字节,则下次读取剩余的600个字节时将可用.另外,如果您接收到的数据大于缓冲区大小,则服务器将收到通知,以防止数据在两者之间丢失.

另一方面,如果您使用的是UDP协议(无连接),则当接收到的数据超过缓冲区大小时,数据将丢失.
It seems that you are using TCP protocol. If you are using TCP protocol, data is stored in a buffer until you read it i.e. if u recieved 1000 bytes but you only read 400 bytes, the next time you read the remaining 600 bytes will be available. Also, if you receieve data that is more than your buffer size, the server will be notified so that data does not get lost in between.

On the other hand, if you are using UDP protocol (connectionless), when you receive data that is more than your buffer size, data will be lost.


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

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