Bug? [SOLVED] Network UDPSocket

RandomCoder

Well-Known Member
Licensed User
Longtime User
Basic4Android version 3.00
Network library version 1.25

Use of CRLF only sends \n when captured using WireShark. Need to use Chr(13) & Chr(10) to work correctly and get \r\n.

Sample code demonstrating the bug (udpSocket1 is a Process Global UDPSocket)...
B4X:
Private Sub M_Search(mx As Int, st As String)
    Dim packet As UDPPacket
    Dim data() As Byte
    Dim msg As String

    ' Compile HTTP broadcast message
    msg = "M-SEARCH * HTTP/1.1" & CRLF & _
        "HOST: 239.255.255.250:1900" & CRLF & _
        "MAN: " & Chr(34) & "ssdp:discover" & Chr(34) & CRLF & _
        "MX: " & mx & CRLF & _
        "ST: " & st & CRLF & CRLF
    Log(msg & CRLF)    'DEBUG

    ' Convert string to UTF8
    data=msg.GetBytes("UTF8")
    ' Initialise packet and send
    packet.Initialize(data, "239.255.255.250", 1900)
    udpSocket1.Send(packet)
End Sub

Sample code in which \r\n is sent correctly...
B4X:
Private Sub M_Search(mx As Int, st As String)
    Dim packet As UDPPacket
    Dim data() As Byte
    Dim msg As String

    ' Compile HTTP broadcast message
    msg = "M-SEARCH * HTTP/1.1" & Chr(13) & Chr(10) & _
        "HOST: 239.255.255.250:1900" & Chr(13) & Chr(10) & _
        "MAN: " & Chr(34) & "ssdp:discover" & Chr(34) & Chr(13) & Chr(10) & _
        "MX: " & mx & Chr(13) & Chr(10) & _
        "ST: " & st & Chr(13) & Chr(10) & Chr(13) & Chr(10)
    Log(msg & CRLF)    'DEBUG

    ' Convert string to UTF8
    data=msg.GetBytes("UTF8")
    ' Initialise packet and send
    packet.Initialize(data, "239.255.255.250", 1900)
    udpSocket1.Send(packet)
End Sub

This was only discovered because some UPNP devices were not replying to the search request due to incorrect termination of the header.

Regards,
RandomCoder
 
Top