Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

SocketIO for Unity not working with Android

Discussion in 'Android' started by chiv33s, Nov 12, 2017.

  1. chiv33s

    chiv33s

    Joined:
    May 25, 2017
    Posts:
    3
    I'm making a Gear VR app and want to use SocketIO to connect the phone to a node server.

    It works fine on my Windows machine/in the unity editor, and has two way communication, however
    when I build the project on android there is no communication, there's no
    error messages or warnings about it in Android Device Monitor saying why it's not connected.

    A quote on SocketIO for Unity reviews says this about the problem:

    "After Unity 5.3, this may not work from android /iOS device as the unity app is built in a more secure way, prohibiting it to access non-ssl endpoints. I have spent 4 hours pulling my hairs off figuring this out as it was working perfectly from the editor, but not from the android/iOS device.

    if you have the server address as "http://localhost:3000", then you must change the way unity behaves for android and iOS platforms:

    From command line, just invoke :
    /usr/libexec/PlistBuddy -c "Add NSAppTransportSecurity:NSAllowsArbitraryLoads bool true" /Applications/Unity/Unity.app/Contents/Info.plist"


    (The quote can be found here: https://www.assetstore.unity3d.com/en/#!/content/21721)

    But this fix seems to be for OSX and not Windows.

    Does anyone have any ideas for either a fix, or an alternative or just general information on the matter?
     
  2. onikamal

    onikamal

    Joined:
    Nov 21, 2017
    Posts:
    2
    I have the same issue, did you manage to resolve it? If yes, can you help share how to do it. Thanks
     
  3. chiv33s

    chiv33s

    Joined:
    May 25, 2017
    Posts:
    3
    Hey,

    Nope, still no luck, I've been trying to create a HTTPS server instead of HTTP but that doesn't work.

    I also cant find ANY information on how Unity or Android stops/restricts the communication to HTTP servers, and annoyingly there doesn't seem to be any errors on my Android app to point me in any directions either.

    If I find a solution I'll post the answer but it's looking less likely the more I look into it...
     
  4. chiv33s

    chiv33s

    Joined:
    May 25, 2017
    Posts:
    3
    OK, I just tried from scratch again and SocketIO for Unity DID work, you have to change your URL in SocketIOComponent to your computers IP address followed by the port, I did try this before and it didn't work but maybe something else was the problem at that time.

    It seems to work fine now, albeit laggy but that's a different problem to solve!
     
    Last edited: Nov 23, 2017
  5. onikamal

    onikamal

    Joined:
    Nov 21, 2017
    Posts:
    2
    Hi, thanks for the reply.

    I manage to make it work with HTTPS but still no clue for HTTP. I will try to find workaround on this.

    Thanks again for your help!
     
  6. Tushar_kmphasis

    Tushar_kmphasis

    Joined:
    Oct 5, 2019
    Posts:
    7
    Any one find Solution for HTTPS server? over HTTP is works well. there is some Connection problem with HTTPS. if any one have solution then post it.
     
  7. fidelsoto

    fidelsoto

    Joined:
    Aug 7, 2012
    Posts:
    87
    How did it work for you over HTTP?
     
  8. Tushar_kmphasis

    Tushar_kmphasis

    Joined:
    Oct 5, 2019
    Posts:
    7
    I used the the Unity package Socket.io it is perfectly work with HTTP
     
  9. astechnolabs

    astechnolabs

    Joined:
    Jul 11, 2021
    Posts:
    20
    Kindly provide link which Unity package Socket.IO is work, there are lots of github libraries named socket for unity nd all so..
     
  10. unity_3E70F162E01439091F36

    unity_3E70F162E01439091F36

    Joined:
    Apr 10, 2023
    Posts:
    1
    is here any one has used socket for mobile devices ??