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

Having problems sending a UDP packet from a Android device

Discussion in 'Android' started by Vaupell, Jan 4, 2015.

  1. Vaupell

    Vaupell

    Joined:
    Dec 2, 2013
    Posts:
    301
    Hi guys.

    I'm the learning stages of DIY networking, and sofar i have succesfully been able to communicate between
    different pc's both over Lan but also over the internet. Even Arduino units, without any major issues.

    Android with unity is however another matter.. :(

    I'm using unity Pro, android free, but i got the "Good old sockets" asset to replace the system.net.sockets
    and while it works fine in "gamemode" in unity editor, I'm not able to send from any of my android devices.
    I've setup a receiving server, that reads and displays all udp packets recieved. also testet both lan and www works.

    Now doing this with an android build does not work at all.

    This is the part I use for the sending of the udp packet, and works for all other devices other than android.

    IP + IPport is obviously the public ip and port.
    sendData is the actual string/msg im trying to send

    Code (csharp):
    1.  
    2.     void sendUDP(string sendData){
    3.         byte[] myData = System.Text.ASCIIEncoding.ASCII.GetBytes (sendData);
    4.         IPEndPoint ep = new IPEndPoint (IPAddress.Parse (IP), IPport);      
    5.         Socket myClient = new Socket (AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
    6.         myClient.SendTo(myData, ep);
    7.         myClient.Close();
    8.     }
    9.  
    I'm not getting any errors, freezes, or indication of any kind that there is a problem, on the device.
    However the message is never recieved, now considering it works from all sorts of other things like
    different computers, avr microprocessors, it's very odd that i cant send from the android device.

    The device is connected to the web via WIFI, so it should be able to "just broadcast" .

    Any suggestions ?
     
    Alessandruus likes this.
  2. rodtuckwell_unity

    rodtuckwell_unity

    Joined:
    Dec 8, 2020
    Posts:
    9
    Did you ever get to the bottom of this?

    regards
     
  3. Vaupell

    Vaupell

    Joined:
    Dec 2, 2013
    Posts:
    301
    Well, dang,, old post.. Yes i got it sorted, but now i dont have the project anymore, it was handed over.
    So not a clue what happened or the code. sorry. But i do remember it was Unity 5 Pro, with Android Pro expansion.

    these days i only work on PC/Linux development, and not the mobile market at all.