iOS Question Error sending data: 49 [SOLVED]

Didier9

Well-Known Member
Licensed User
Longtime User
I get this error message when sending data via UDP.

The port is opened with this:
B4X:
UDPSck1.Initialize( "UDPSck1", Port, 4096 )
which does not cause a fault,
and the data is sent with this:
B4X:
Public Buffer() As Byte
c = "Test"
Buffer = c.GetBytes( "UTF8" )
Dim Packet As UDPPacket
Packet.Initialize( Buffer, TargetIP, Port )
UDPSck1.Send( Packet )
Target IP is set to "255.255.255.255" (broadcast) and the port is 8899.

(I may add this code works under B4A)

Just found that a different method must be used to send broadcast packets, so I have changed the last line to:
B4X:
    If TargetIP = "255.255.255.255" Then
        UDPSck1.SendBroadcast( Packet )
    Else
        UDPSck1.Send( Packet )
    End If
but I am still getting error 49, whether I send to the broadcast address or the actual IP address of the target.

This looks similar to this issue:
https://www.b4x.com/android/forum/t...-2-the-udp-send-data-error.74571/#post-473891
 
Last edited:

Didier9

Well-Known Member
Licensed User
Longtime User
Here is the log (the app does not crash):
B4X:
Copying updated assets files (2)
Application_Start
Didier's iPad
iPad
iOS
Connection successful
Application_Active
Sending !0Z$+8 to 10.0.0.5
error sending data: 49
Sending !0Z$+8 to 10.0.0.5
error sending data: 49
Sending !0Z$+8 to 10.0.0.5
error sending data: 49

The message "error sending data: 49" does not come from the app, it is light grey text that's coming from the device itself apparently.

I have uploaded the project, it is a cut down version of the B4A app I have been working on for a couple of weeks.
 

Attachments

  • LightController.zip
    12.3 KB · Views: 240
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
10.0.0.5
Are you testing it on a real device?
yes, I use an iPad Mini HD (WiFi only) and the target is a microcontroller with a WiFi module. That setup works fine with 2 android devices running essentially the same code as the B4I code I uploaded, talking to the target at the same time. Once I register the iPhone 6+ with Apple, I will try it too.
1. Try to set the Port variable to a random port (23442). Currently it is set to 0.
I believe I have tried that but I will try again later today. It may be that 8899 is privileged (below 10,000), so maybe Apple does not want me to use it. Error message says: "Can't assign requested address", but it may be the port number that's not good. I can reconfigure my target to use a higher port. That's on the list too.
2. Try to turn on airplane mode and enable wireless.
The iPad is WiFi only.
I do most of my development and testing with non-provisioned Android devices (because I have a bunch laying around) and aside from weird issues with WiFi and Android (when using a non-internet accessible hot spot, about which I have posted about earlier), this Android app is actually pretty solid with the target connected to my home network.

As an aside, originally the app would continuously try to communicate with the target using the broadcast address. Apparently the router did not like that and the connection would degrade rapidly after a minute or two, then it would work again if I waited a while. I am pretty sure that it was the router stopping to broadcast the packets (my target is connected via WiFi also). I now collect the target's IP address when I get the first response and from then on I use that address to send commands (unless it times out 5 times, then I restart broadcasting). This works perfectly. My Android devices have been communicating solidly with the target for several days now without reboot or reset of any kind.
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
The destination port was supposed to be set to 8899, the port number my target is listening to. The sending port was supposed to be left at 0, to let the OS use whatever port it wants. I must have chopped the line setting the destination port when I imported the code from the Android app. I did remove a bunch of non-essential code that I did not want to mess with at first on the iOs app. Your remark that it was not initialized (set to 0) prompted me to check.

Now after setting the destination port in the UDPSck1.Send() function, it is working, thank you so much!

I can't believe I spent so much time on that :(
 
Upvote 0
Top