Android的DatagramSocket的接收缓冲区大小 [英] Android DatagramSocket receive buffer size

查看:1498
本文介绍了Android的DatagramSocket的接收缓冲区大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置/增加一个数据报套接字的接收缓冲区的大小。我想做到这一点,因为我送的位于同一本地网络上的PC和Android设备之间传送数据时,我想测试,如果增加缓冲区大小会有什么影响在减少该UDP遇到了一些随机数据包丢失数据包丢失。我尝试使用下面的code设置缓冲区的大小。

  DatagramSocket的插座=新的DatagramSocket();
socket的(655360);

再后来就(之前,我开始从套接字读取),我检查接收缓冲区大小如下:

  Log.i(TAG,大小+ socket.getReceiveBufferSize());

不过,日志消息始终显示的163840缓冲区大小。
这有什么code中的问题?我应该设置以另一种方式接收缓冲区的大小。

感谢


解决方案

  

日志消息始终显示的163840缓冲区大小。


这就是这个平台给了你。


  

这有什么code中的问题?


没有。你需要阅读的Javadoc。该平台可以调整您提供向上或向下的价值。 因为 SO_RCVBUF 是一种提示,想要验证大小缓冲区设置为应该调用应用程序 getReceiveBufferSize()。

您不需要插座接收640K缓存。数据包丢失主要发生在网络中,只有在目标,如果你正在阅读缓慢。

I am trying to set/increase the receive buffer size of a datagram socket. I would like to do this since I am experiencing some random packet loss when sending data between a PC and the Android device which lie on the same local network and I would like to test if increasing the buffer size would have any effect in reducing this UDP packet loss. I am trying to set the buffer size using the below code.

DatagramSocket socket = new DatagramSocket();
socket.setReceiveBufferSize(655360);

and then later on (before I start reading from the socket) I check the receive buffer size as follows:

Log.i(TAG, "Size: " + socket.getReceiveBufferSize());

However, the log message always displays a buffer size of 163840. What is the problem with this code? Should I set the receive buffer size in another way.

Thanks

解决方案

The log message always displays a buffer size of 163840.

That's what the platform gave you.

What is the problem with this code?

Nothing. You need to read the Javadoc. The platform may adjust the value you supply up or down. "Because SO_RCVBUF is a hint, applications that want to verify what size the buffers were set to should call getReceiveBufferSize()."

You don't need a socket receive buffer of 640k. Packet loss happens mostly in the network, and only at the target if you are slow reading.

这篇关于Android的DatagramSocket的接收缓冲区大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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