iOS Question UDPSocket.send returns "error sending data: 13"

Status
Not open for further replies.

DickD

Active Member
Licensed User
I'm trying to use the code shown below to send my ip address to the broadcast address of the local wifi router. Note that receiving data using UDPSocket works OK. Only when sending do I get error 13. It's odd that this error is not trapped with try/catch. This same code works fine on Android devices. Using B4i 4.0 and IOS 10.3.3.

B4X:
Sub Process_Globals
 Dim MyIP, Address as string
 Dim broadcasttimer As Timer
 Dim autodiscover2 As UDPSocket
 Dim serializator As B4XSerializator
End Sub

Sub Start
 MyIP = server.GetMyWifiIP
 Address = us.GetBroadcastAddress
 autodiscover2.Initialize("",11919, 100)
 broadcasttimer.Initialize("BroadcastTimer", 3000)
 broadcasttimer.Enabled = True
End Sub

Private Sub BroadcastTimer_Tick
 If Address <> "" Then
 Dim up As UDPPacket
 up.Initialize(serializator.ConvertObjectToBytes(MyIP), Address, 11919)
 autodiscover2.Send(up)
 End If
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
It's odd that this error is not trapped with try/catch
The data is sent asynchronously. It is sent at some point after the Send method was called.

iNetwork v1.32 is attached. It includes a new SendBroadcast method which you should use when sending to the broardcast address.

Copy the XML to the internal libraries project.
 

Attachments

  • iNetwork.zip
    90.6 KB · Views: 255
Upvote 0

DickD

Active Member
Licensed User
The data is sent asynchronously. It is sent at some point after the Send method was called.

iNetwork v1.32 is attached. It includes a new SendBroadcast method which you should use when sending to the broardcast address.

Copy the XML to the internal libraries project.
That did it. Thanks.
 
Upvote 0

RaymondHung

Member
Licensed User
Longtime User
I have the same problem, Using B4i 6.5 and IOS 12.4.8, Please help answer.

B4X:
Sub Process_Globals
        Dim UDPSocket1 As UDPSocket
End Sub

Private Sub Application_Start (Nav As NavigationController)   
    UDPSocket1.Initialize("UDP", 30303, 8000)
End Sub

Public Sub DiscoverIP
    Dim Packet As UDPPacket
    Dim data() As Byte
    Dim strCmd As String = "Discovery"
    
    data = strCmd.GetBytes("UTF8")
    Packet.Initialize(data, "255.255.255.255", 30303)
    UDPSocket1.send(Packet)   
End Sub
 
Upvote 0
Status
Not open for further replies.
Top