http://stackoverflow.com/questions/2811006/what-is-a-good-buffer-size-for-socket-programming

问题:

We are using .Net and sockets.

The server is using the Socket.Sender(bytes[]) method so it just sends the entire payload.

On the other side we are clients consuming the data.

Socket.Receive(buffer[]).

In all the examples from Microsoft (and others) they seem to stick with a buffer size of 8192.

We have used this size but 【every now and then不时地,常常】 we are sending data down to the clients that exceeds this buffer size.

Is there a way of determining how much data the server's sent method sent us? What is the best buffer size?

回答:

Even if you're sending more data than that, it may well not be available in one call to Receive.

You can't determine how much data the server has sent - it's a stream of data, and you're just reading chunks at a time.

You may read part of what the server sent in one Send call, or you may read the data from two Send calls in one Receive call.

8K is a reasonable buffer size - not so big that you'll waste a lot of memory, and not so small that you'll have to use loads of wasted Receive calls.

4K or 16K would quite possibly be fine too... I personally wouldn't start going above 16K for network buffers - I suspect you'd rarely fill them.

You could experiment by trying to use a very large buffer and log how many bytes were received in each call - that would give you some idea of how much is generally available -

but it wouldn't really show the effect of using a smaller buffer.

What concerns do you have over using an 8K buffer?

If it's performance, do you have any evidence that this aspect of your code is a performance bottleneck?

最新文章

  1. SQL Server 从数据库中查询去年的今天的数据的sql语句
  2. mysql高可用架构
  3. cname和CDN
  4. 2dx中文乱码问题
  5. IO流--文件处理
  6. c# string 数组转 list
  7. adb调试命令详解-2016.02.01
  8. 退出程序是跳过屏幕自检 比如 必输 EXIT-COMMAND
  9. W5500问题集锦(一)
  10. 关于ClassLoader
  11. 扩大按钮 btn 响应区域
  12. accp8.0转换教材第2章初识MySQL
  13. 在javascript里 string 和 int 类型转换
  14. 浅谈Java的主要学习要点_上海尚学堂java培训课程思维导图
  15. 关于Servlet的一些归纳(1)
  16. 如何修改Tomcat的默认项目发布路径
  17. bootstrap常见的面试题
  18. js实现全选/全不选、反选
  19. Chrome查看HTTP
  20. 字符串--C++系列

热门文章

  1. Bullet:ORACLE Using SQL Plan Management(一)
  2. Xmind的使用
  3. Python使用Flask框架,结合Highchart处理csv数据(引申-从文件获取数据--从数据库获取数据)
  4. linux(Ubuntu16)下切换python2和python3(转)
  5. Django DTL模板语法中的循环的笔记
  6. Maven_在Eclipse中执行Maven命令
  7. pyhthon第一个小脚本——文件备份
  8. [luoguP3565] [POI2014]HOT-Hotels(dfs)
  9. Codeforces Round #232 (Div. 2) On Sum of Fractions
  10. Uva679 Dropping Balls