Search Unity

UdpClients, working on pc, but android causes SocketException Access Denied - Permissions Problem

Discussion in 'Multiplayer' started by Boardley, Nov 25, 2014.

  1. Boardley

    Boardley

    Joined:
    Nov 14, 2014
    Posts:
    14
    Hi there,
    I am working on network, and using System.Net.UdpClient, and it works very well on my PC, both editor and standalone build.
    but i come to trouble when talking about android. On it i am receiving this error: "SocketException Access Denied"
    I am sure this is caused by the permissions of android manifest, but i saw that the manifest is correct, it has the permission of "android.permission.INTERNET"
    Code (csharp):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3.     <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.BlaCorp.BlaBlaBlaBlaApp" android:theme="@android:style/Theme.NoTitleBar" android:versionName="1.4.7.1" android:versionCode="1" android:installLocation="preferExternal">
    4.         <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
    5.         <application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="false">
    6.         <activity android:name="com.unity3d.player.UnityPlayerNativeActivity" android:label="@string/app_name" android:screenOrientation="sensorLandscape" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">
    7.         <intent-filter>
    8.         <action android:name="android.intent.action.MAIN" />
    9.         <category android:name="android.intent.category.LAUNCHER" />
    10.         <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
    11.         </intent-filter>
    12.         <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    13.         <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
    14.         </activity>
    15.         </application>
    16.         <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="21" />
    17.         <uses-feature android:glEsVersion="0x00020000" />
    18.         <uses-permission android:name="android.permission.INTERNET"/>
    19.         <uses-feature android:name="android.hardware.sensor.accelerometer" />
    20.         <uses-feature android:name="android.hardware.touchscreen" android:required="false" />
    21.     </manifest>
    22.  
    what is the cause?
    what am I missing?
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    I assume you have Unity Android Pro? Else this should fail compiling.
    I don't know about the manifest but you could check the Player Settings for Android. There should be a checkbox for "Internet Access" or similar. Maybe that helps.
     
  3. Boardley

    Boardley

    Joined:
    Nov 14, 2014
    Posts:
    14
    I have Unity Pro, with Android Pro, and Internet Access Options are Auto and Require, I tried both, but i get same result
     
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    It could be the code stripping. Or maybe the UdpClient is not available on Android. We use the Socket class directly, so I can only guess.
     
  5. Boardley

    Boardley

    Joined:
    Nov 14, 2014
    Posts:
    14
    mmh, it is strange, because i have 2 versions of this, the first one has only the sending and receiving messages, the second one is little bit more improved. the first version is working properly, but the second doesn't. So i tought it might be caused by AndroidManifest.xml

    UdpClient is referenced to Socket,
    Code (csharp):
    1.  
    2. public class UdpClient : IDisposable {
    3.      public Socket client ...
    4. }
    5.  
    I am going to see something, i will let you know