简体   繁体   中英

C# webclient on WIFI

I implemented a simple Webclient to upload files to a web server. 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). The uploads stops about every 5 seconds and then most often continues but sometimes doesnt. 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.

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 ? 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).

Offices tend not to have so many 2.4GHz sources as at home.

Try disconnecting your neighbors' electrical appliances. A small EMP device should suffice^. 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 . 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. 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.

Finally you can try to switch your WIFI channel to 5GHz if they all work on that frequency. Its meant to be clearer. However, ultimately as more people use the 2.4GHz radio range, WIFI will get worse.

^This SO user does not condone the usage of electronic/nuclear warfare weaponry for the purpose of reducing dropped packets on you home 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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