Android的无线带宽 [英] Android Wifi Bandwidth

查看:248
本文介绍了Android的无线带宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我被赋予了任务制定关于Nexus 7平板电脑,这将与PC机通过TCP套接字使用WiFi来西藏羊八井Android应用程序。

Recently I was given a task to develop Android app on Nexus 7 tablet, which would be conneted with pc via tcp sockets using wifi.

特别我必须通过图像流(uncom pressed BMP为例)平板电脑。所以我做了简单的测试来检查带宽和由结果失望的。我只是在WiFi信号SOURSE面前与我的平板电脑选址,这是写的连接速度每秒54MB,但我只得到〜每秒考虑测试结果16Mb的。

Particularly I had to pass stream of images (uncompressed BMP for example) to tablet. So I made simple test to check bandwidth and was dissapointed by results. I'm siting with my tablet just in front of wifi signal sourse, it's written that connection speed is 54Mb per sec, but I get only ~16Mb per sec considering test results.

测试code:

PC:

    public static void main(String[] args) throws Exception 
    {
        Socket socket = new Socket(androidIpAddr, port);

        OutputStream output = socket.getOutputStream();

        byte[] bytes = new byte[1024 * 100]; // 10K
        for (int i = 0; i < bytes.length; i++) {
            bytes[i] = 12;
        } // fill the bytes

        // send them again and again
        while (true) {
            output.write(bytes);
        }
     }

Android的:

Android:

public class MyActivity extends Activity {
/**
 * Called when the activity is first created.
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);       

    new Thread(new Runnable() 
      {
        public void run() 
         {
           ServerSocket server = new ServerSocket(port);
           Socket socket = server.accept();

           InputStream input = socket.getInputStream();
           long total = 0;
           long start = System.currentTimeMillis();

           byte[] bytes = new byte[1024 * 100]; // 10K

           // read the data again and again
           while (true) 
           {
             int read = input.read(bytes);
             total += read;
             long cost = System.currentTimeMillis() - start;
             if (cost > 100) 
             {
               double megaBytes = (total / (1024.0 * 1024));
               double seconds = (cost / 1000.0);

               System.out.println("Read " + total + " bytes, speed: " + megaBytes / seconds + " MB/s");
               start = System.currentTimeMillis();
               total = 0;
             }
           }                
        }
    }).start();

}

}

我是怎么错过了吗?

推荐答案

好吧,首先无线是54Mbps的是54×1024×1024每秒的的。因此,最高为6.75 MB /秒。

Ok, first Wifi that is 54Mbps is 54 x 1024 x 1024 bits per second. So maximum 6.75 MB/s.

我这样做,在我的Windows 54 Mbps的7箱报道我的网络上的实验。我的Windows 7盒(服务器)和XP箱(客户端)之间,我使用上面基本上是code达到3.0 MB /秒。

I did the experiment on my network that reports as 54 Mbps in my windows 7 box. Between my Windows 7 box (server) and XP box (client) I achieved 3.0 MB/s using basically the code above.

我然后跑同样的code我的Nexus 7(服务器)和XP(客户端)之间,得到0.3 MB /秒。因此,一个显著落客的速度。我把下面的服务器线程的构造函数:

I then ran the same code between my Nexus 7 (server) and XP (client) and got 0.3 MB/s. So a significant drop-off in speed. I put the following in the constructor of the server thread:

android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);

和在清单:

<uses-permission android:name="android.permission.RAISED_THREAD_PRIORITY"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

我也感动路由器附近,转身无线关闭,然后重新打开。据报道了的Nexus 7为54Mbps的,当我运行它我得到了3.0 MB /秒。

I also moved near the router and turned wifi off and then back on. It reported on the Nexus 7 as 54Mbps and when I ran it I got 3.0 MB/s.

所以在这一点相同的结果作为Windows 7的和理论的网络吞吐量的44%。

So at this point same outcome as Windows 7 and about 44% of theoretical network throughput.

使用多个TCP连接可以让我们更接近100%的吞吐量。

Using more than one TCP connection may allow us to get closer to 100% throughput.

这篇关于Android的无线带宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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