简体   繁体   English

WIFI上的C#WebClient

[英]C# webclient on WIFI

I implemented a simple Webclient to upload files to a web server. 我实现了一个简单的Webclient,将文件上传到Web服务器。 Here is the relevant part of my code: 这是我的代码的相关部分:

 private bool fileUploadValid = new bool();
    string fileLocation = "D:/testvideo.avi";
    WebClient client = new WebClient();

    public MainWindow()
    {
        InitializeComponent();

        client.UploadFileCompleted += new UploadFileCompletedEventHandler(UploadFileCallback);

        // Specify a progress notification handler.
        client.UploadProgressChanged += new UploadProgressChangedEventHandler(UploadProgressCallback);
        client.Headers.Add("Content-Type", "binary/octet-stream");

        UploadFileInBackground("http://xxx/videolibrary/fileUpload.php", fileLocation);
    }

    public void UploadFileInBackground(string address, string fileName)
    {

        Uri uri = new Uri(address);
        client.UploadFileAsync(uri, "POST", fileLocation);


        Console.WriteLine("File upload started.");
       // fileUploadValid = false;

    }

When I try to upload a file over wifi it is very slow (although my wifi signal strength is perfect). 当我尝试通过wifi上传文件时,速度非常慢(尽管我的wifi信号强度很完美)。 The uploads stops about every 5 seconds and then most often continues but sometimes doesnt. 上载大约每5秒钟停止一次,然后大多数情况下继续执行,但有时没有。 The stopping of the upload is my biggest problem because it will not throw any error (no timeout or anything else). 停止上传是我最大的问题,因为它不会引发任何错误(没有超时或其他任何错误)。 When I connect my laptop to a ethernet cable there is no problem and the upload finishes in no time. 当我将笔记本电脑连接到以太网电缆时,没有问题,并且上传很快就完成了。 Can somebody help me out? 有人可以帮我吗?

I also tried the same code at my University, where it seems to work fine. 我还在大学里尝试了相同的代码,在这里看来效果很好。 There is a WPA netwerk there where I am here on a WEP signed netwerk. 有一个WPA网络,我在这里是WEP签名的网络。

Do you or your neighbors own any of the following: Microwave, Smartphone, Another Wifi AP, Bluetooth radio, DECT cordless phone, Car, Zigbee or any other 2.4GHz radio source ? 您或您的邻居是否拥有以下任何一项: 微波,智能手机,另一个Wifi AP,蓝牙无线电,DECT无绳电话,汽车,Zigbee或任何其他2.4GHz无线电源 It sounds like there is intermittent dropped packets in your network. 听起来您的网络中存在间歇性丢弃的数据包。 Remember there are multiple elements that can drop the ball in a network. 请记住,有多个因素可以使网络陷入困境。 In the residential setting I personally find that the Wifi PHY layer performs very very badly (but good enough for most people, since the TCP stack tends to handle dropped packets well). 在住宅环境中,我个人发现Wifi PHY层的性能非常差(但对大多数人来说足够好,因为TCP堆栈倾向于很好地处理丢弃的数据包)。

Offices tend not to have so many 2.4GHz sources as at home. 办公室往往没有家里那么多的2.4GHz信号源。

Try disconnecting your neighbors' electrical appliances. 尝试断开邻居的电器。 A small EMP device should suffice^. 小型EMP设备就足够了。 Alternatively you could try shielding your house from your neighbors' EM emissions using the tin foil wall paper, constructing what is called a Faraday Cage . 或者,您可以尝试使用锡纸墙纸来屏蔽邻居的EM辐射,从而建造房屋,建造所谓的法拉第笼 Remember to include a tin foil hat *. 请记住包括锡纸帽子 *。 This will reduce the EM emissions from your brain interfering with the transfer. 这将减少您的大脑干扰传输的电磁辐射。

Also try isolating your WIFI appliances from the mains. 另外,请尝试将WIFI设备与市电隔离。 Attach them using surge protectors, this can help to reduces interference from appliances such as your washing machine and TV (or in my case, once, a pair of HomePlugs ) that can cause line noise from generating radio noise. 使用电涌保护器将它们连接起来,可以帮助减少来自洗衣机和电视等设备的干扰(在我的情况下,是一对HomePlug ),这些干扰可能导致线路噪声产生无线电噪声。

Finally you can try to switch your WIFI channel to 5GHz if they all work on that frequency. 最后,如果它们均在该频率下工作,则可以尝试将WIFI频道切换到5GHz。 Its meant to be clearer. 它的意思是更清楚。 However, ultimately as more people use the 2.4GHz radio range, WIFI will get worse. 但是,最终随着越来越多的人使用2.4GHz无线电范围,WIFI会变得更糟。

^This SO user does not condone the usage of electronic/nuclear warfare weaponry for the purpose of reducing dropped packets on you home wifi. ^此SO用户不宽容使用电子/核战争武器,以减少家庭wifi上丢失的数据包。

*NB The tin foil hat is included for humor as I do know how constructing a Faraday Cage in your house will look to your neighbors. * NB锡纸帽子是出于幽默目的,因为我确实知道在您的房屋中建造法拉第笼会怎样向邻居展示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM