iOS Question New post (UDPSocket.send returns "error sending data: 13")

RaymondHung

Member
Licensed User
Longtime User
When I use UDPSocket, it returns "error sending data: 13", do u know what is the problem?
I using B4i 6.5 and IOS 12.4.8, Hope you can help, Thanks.
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
 
When I use UDPSocket, it returns "error sending data: 13", do u know what is the problem?
I using B4i 6.5 and IOS 12.4.8, Hope you can help, Thanks.
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
Have you looked at this thread?

Walter
 
Upvote 0
My guess: 255.255.255.255 is an invalid IP address. That's a network mask, not a broadcast address.
 
Upvote 0
1) Check firewall settings. Maybe a port is closed.
2) Packet.Initialize(data, "255.255.255.255", 30303)
Use UDPSocket1.GetBroadcastAddress instead of "255.255.255.255"
3) UDPSocket1.send(Packet)
Replace to UDPSocket1.SendBroadcast (Packet)
4) It seems to me it's necessary to make a delay after UDPSocket.Initialize, for example, Sleep (1).
 
Last edited:
Upvote 0
it's not been mentioned, but io error 13 is permission denied. you're doing something the system doesn't like. generally, everybody can send a broadcast, so i'd be looking at a port issue. also, not clear who's sending the packet.
 
Upvote 0
Packet.Initialize(data, "255.255.255.255", 30303)
2) Packet.Initialize(data, "255.255.255.255", 30303)
it's not been mentioned, but io error 13 is permission denied. you're doing something the system doesn't like. generally, everybody can send a broadcast, so i'd be looking at a port issue. also, not clear who's sending the packet.
255.255.255.255 is not a valid broadcast address. This issue needs to be resolved first before one can continue with this issue, since fixing this issue (using a correct broadcast address) may fix the issue at hand (io error 13). Please see this Wikipedia entry on how to determine the broadcast address for a network: https://en.wikipedia.org/wiki/Broadcast_address.

Note:
 
Upvote 0
Thank you very much for your help. After I revised it with your comments,
"error sending data: 13" did not appear, but no response was received in
UDPSocket1_PacketArrived. I use the same settings in B4A and Windows and it works normally.
I test UDPSocket1.GetBroadcastAddress = 127.0.0.1
 
Upvote 0
Sorry everyone, I made a mistake on the name, it should be "UDP_PacketArrived". Now it works normally.
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.SendBroadcast(Packet)
End Sub

Sub UDP_PacketArrived(Packet As UDPPacket)
    Dim msg, IP, mac, otif As String
    
    IP = Packet.HostAddress
    msg = BytesToString(Packet.Data, Packet.Offset, Packet.Length, "UTF-8")
                  



End Sub
 
Upvote 0
Back
Top