Didier9 Well-Known Member Licensed User Longtime User Jun 24, 2018 #1 I get this error message when sending data via UDP. The port is opened with this: Code: Copy UDPSck1.Initialize( "UDPSck1", Port, 4096 ) which does not cause a fault, and the data is sent with this: Code: Copy 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: Code: Copy 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: Jun 25, 2018
I get this error message when sending data via UDP. The port is opened with this: Code: Copy UDPSck1.Initialize( "UDPSck1", Port, 4096 ) which does not cause a fault, and the data is sent with this: Code: Copy 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: Code: Copy 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
Erel B4X founder Staff member Licensed User Longtime User Jun 25, 2018 #2 Can you post the logs? Upvote 0
Didier9 Well-Known Member Licensed User Longtime User Jun 25, 2018 #3 Erel said: Can you post the logs? Click to expand... Of course, not sure why I did not, but it will be tonight. Thanks Upvote 0
Erel said: Can you post the logs? Click to expand... Of course, not sure why I did not, but it will be tonight. Thanks
Didier9 Well-Known Member Licensed User Longtime User Jun 26, 2018 #4 Here is the log (the app does not crash): Code: Copy 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 LightController.zip 12.3 KB · Views: 611 Upvote 0
Here is the log (the app does not crash): Code: Copy 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.
Erel B4X founder Staff member Licensed User Longtime User Jun 26, 2018 #5 Error codes: http://www.workers.com.br/manuais/53/html/tcp53/mu/mu-7.htm What is the device ip address? Are you testing it on a real device? 1. Try to set the Port variable to a random port (23442). Currently it is set to 0. 2. Try to turn on airplane mode and enable wireless. Upvote 0
Error codes: http://www.workers.com.br/manuais/53/html/tcp53/mu/mu-7.htm What is the device ip address? Are you testing it on a real device? 1. Try to set the Port variable to a random port (23442). Currently it is set to 0. 2. Try to turn on airplane mode and enable wireless.
Didier9 Well-Known Member Licensed User Longtime User Jun 26, 2018 #6 Erel said: Error codes: http://www.workers.com.br/manuais/53/html/tcp53/mu/mu-7.htm What is the device ip address? Click to expand... 10.0.0.5 Erel said: Are you testing it on a real device? Click to expand... 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. Erel said: 1. Try to set the Port variable to a random port (23442). Currently it is set to 0. Click to expand... 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. Erel said: 2. Try to turn on airplane mode and enable wireless. Click to expand... 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
Erel said: Error codes: http://www.workers.com.br/manuais/53/html/tcp53/mu/mu-7.htm What is the device ip address? Click to expand... 10.0.0.5 Erel said: Are you testing it on a real device? Click to expand... 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. Erel said: 1. Try to set the Port variable to a random port (23442). Currently it is set to 0. Click to expand... 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. Erel said: 2. Try to turn on airplane mode and enable wireless. Click to expand... 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.
Didier9 Well-Known Member Licensed User Longtime User Jun 27, 2018 #7 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
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