Bug 57351 - System.Net.Sockets.SocketException: mono-io-layer-error (10013) when sending UDP package to certain port
Summary: System.Net.Sockets.SocketException: mono-io-layer-error (10013) when sending ...
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 7.3 (15.2)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Marek Habersack
URL:
Depends on:
Blocks:
 
Reported: 2017-06-10 04:19 UTC by biruto05
Modified: 2017-06-29 10:16 UTC (History)
6 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Sample app to re-produce the problem (12.32 KB, application/x-zip-compressed)
2017-06-10 04:19 UTC, biruto05
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description biruto05 2017-06-10 04:19:55 UTC
Created attachment 22822 [details]
Sample app to re-produce the problem

I'm using UdpClient to send a single byte package to all machines in local network (discovery process).

The code snippet is as following:

var msgData = new List<byte> {(byte)'D'};
var udpClient = new UdpClient(0, AddressFamily.InterNetwork);
udpClient.Send(msgData.ToArray(), msgData.Count, new IPEndPoint(IPAddress.Parse("192.168.51.255"), 1883));

This code work correctly with Xamarin.Android 7.1 (along with Xamarin 4.3)
However, after upgrading to Xamarin.Android 7.3 (along with Xamarin 4.5), I am getting an exception

06-10 00:14:59.908 I/MonoDroid( 1984): System.Net.Sockets.SocketException (0x80004005): mono-io-layer-error (10013)
06-10 00:14:59.908 I/MonoDroid( 1984):   at System.Net.Sockets.Socket.SendTo (System.Byte[] buffer, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags socketFlags, System.Net.EndPoint remoteEP) [0x00066] in <a547bd0d78184f26ab08d022f013c1e1>:0 
06-10 00:14:59.908 I/MonoDroid( 1984):   at System.Net.Sockets.UdpClient.Send (System.Byte[] dgram, System.Int32 bytes, System.Net.IPEndPoint endPoint) [0x00067] in <a547bd0d78184f26ab08d022f013c1e1>:0 
06-10 00:14:59.908 I/MonoDroid( 1984):   at App2.MainActivity.SendDiscoveryPackage () [0x00067] in C:\Users\dangt\Documents\Visual Studio 2017\Projects\App2\App2\MainActivity.cs:54 
06-10 00:14:59.908 I/MonoDroid( 1984):   at App2.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x00009] in C:\Users\dangt\Documents\Visual Studio 2017\Projects\App2\App2\MainActivity.cs:33 
06-10 00:14:59.908 I/MonoDroid( 1984):   at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x0000f] in <d855bac285f44dda8a0d8510b679b1e2>:0 
06-10 00:14:59.908 I/MonoDroid( 1984):   at (wrapper dynamic-method) System.Object:af193fbf-cfd4-4f6f-ac8e-57b6ec4196d1 (intptr,intptr,intptr)

This error is tested on Samsung phone running android 7 and Sony phone running android 6.

I attached the project to reproduce this error.
Comment 1 khoanguyen 2017-06-13 04:48:44 UTC
Please fix this bug ASAP!
We face with same issue!
Comment 2 Leandro Menezes 2017-06-13 11:49:52 UTC
I'm facing the same exception when using System.Net.Http.HttpClient.PostAsync(string requestUri, HttpContent content)
Comment 3 Leandro Menezes 2017-06-13 12:18:27 UTC
Obs: It DOES work when using the emulator
Comment 4 Marek Habersack 2017-06-14 11:01:26 UTC
The attached test case works correctly with the current xamarin-android/master. After running it on Android 7.1.1 (Nexus 9) I see in logcat the following message:

06-14 12:52:42.288  2920  2920 I Discovery: UDP package is sent successfully.

from the code:

> private static void SendDiscoveryPackage()
> {
>    var msgData = new List<byte> {HeaderByte};
>    using (var udpClient = new UdpClient(0, AddressFamily.InterNetwork))
>    {
>        try
>        {
>            udpClient.Send(msgData.ToArray(), msgData.Count, new IPEndPoint(IPAddress.Parse(SubnetMask), ServerDiscoveryPort));
>            Log.Info("Discovery", "UDP package is sent successfully.");
>        }
>        catch (SocketException se)
>        {
>            Log.Error("Discovery", se.Message);
>            throw;
>        }
>    }
>}

Please test with the current Alpha release of Xamarin.Android (7.3.1.2 as of today) to see if the issue is gone for you.
Comment 5 khoanguyen 2017-06-15 02:34:58 UTC
Hi Marek Habersack

We did a check and it WORKED if android mobile connected to the INTERNET wifi.

For the local wifi (no internet wifi), it still throw this exception:
mono-io-layer-error (10013)


Could you please take a look for it?

Regards
Khoa
Comment 6 khoanguyen 2017-06-15 03:34:05 UTC
Hi Marek Habersack

I want to update a bit:

With local WIFI: 
It WORK when we test with SAMSUNG 7.1 and NEXUS 7.0
It DOESN'T WORK when we run SAMSUNG 6.0 or HUAWEI 7.0

Please take a look and verify with some cases:
INTERNET WIFI
LOCAL WIFI
OS 5.0 TO 7.1.1
SAMSUNG, OPPO, NEXUS, huawei...

Regards
Comment 7 biruto05 2017-06-15 06:53:20 UTC
Hi Marek.

I'm experimenting strange behavior where the attached app only works on some random devices/OS version/network.

I have been testing on:
+ Various phone: Samsung Galaxy S7 (android 7.1.1), Samsung Prime J5 (android 6.0), Sony Ultra Z (android 6.0), Motorola Nexus (android 7.1.0)
+ 2 kind of network: local network with INTERNET connection and local network only.

The sample app seems work on random combination of device-network.
Could you take a look at other phones than your Android 7.1.1 (Nexus 9)?

Thanks.
Comment 8 Jon Goldberger [MSFT] 2017-06-16 01:07:26 UTC
@Marek,

So you said "fix is in Alpha version 7.3.1.2" but that version number is the current stable version. Can you clarify if this fix is in the stable release or in an upcoming release?
Comment 9 Marek Habersack 2017-06-16 09:15:19 UTC
@Jon, I misread the release JSON and thought it was alpha

@Khoa, error 10013 is `WSACCESS`, that is "access denied", interesting... That said, I can't reproduce it on any of my devices, connected to public network or not :(

@Jon, @peterc would you be able to test it on some Samsung devices as per comments 5 through 7?
Comment 10 Jon Goldberger [MSFT] 2017-06-16 20:18:54 UTC
@Marek,

I tested on the only Samsung device I have, an old Samsung Galaxy Tab 2. I could not reproduce the error on that device. 

I also added a button to the test project so I could run it in test cloud and test on more devices. The test passed on all of the following devices:

Android 7.1.2:
   Google Pixel
   Google Pixel XL
   Huawei Nexus 6P
  
Android 7.0:
   Huawei Nexus 6P
   Huawei P10
   Samsung Galaxy S7
   Samsung Galaxy S7 Edge
   Samsung Galaxy S8
   Samsung Galaxy S8 Plus

Android 6.0.1:
   Huawei Nexus 6P
   Samsung Galaxy S7
   Samsung Galaxy S7 Edge
Comment 11 biruto05 2017-06-17 12:08:10 UTC
@Jon

Could you tell me exactly what version of xamarin android you are testing on?
Is it current stable version?
If so, I will keep current environment and prepare test for test cloud also as I am using visual studio 2017 which should always contain latest stable version.

Thanks.

Trinh Dang.
Comment 12 Jon Goldberger [MSFT] 2017-06-19 18:21:27 UTC
@Trinh,

I tested using Xamarin.Android Version: 7.3.1.2 which is the current stable version.
Comment 13 khoanguyen 2017-06-21 10:35:56 UTC
Hi

I upgraded to Xamarin 4.6.0.240 and Xamarin.Adnroid 7.4.0.2 (Beta release) on VS 2015, the bug is still occur.

Regards
Khoa
Comment 14 Marek Habersack 2017-06-21 15:34:32 UTC
I think it might be device + android version specific. We would need to know the exact device and android versions used then hopefully we'd be able to reproduce this issue. Also, a logcat with full context (from the application's start all the way till the crash and some 100 lines after that) would be useful.
Comment 15 Vladimir Djordjevic 2017-06-28 00:46:25 UTC
Hi,

I am facing the the same error code on several devices (android 4.4.2 and 7.0),simulator and Polar M600 (Android Wear 2.0).
Xamarin 4.5.0.486, Xamarin.Android 7.3.1.2 are installed.


Regards
Vlada
Comment 16 Vladimir Djordjevic 2017-06-28 03:46:38 UTC
False alarm, sorry.
Forgot to set UdpClient.EnableBroadcast to true.
Now all works fine on all test devices.


Vlada
Comment 17 biruto05 2017-06-29 01:49:49 UTC
Hi Marek and Jon.

It's working fine on most of devices here also with Xamarin android 7.3.1.2.

I will close this ticket.

Thanks
Comment 18 Marek Habersack 2017-06-29 10:16:03 UTC
Closing as per comment 17, thanks!