#Region -------------------------[ UDP M_Search ]-------------------------
Private Sub Initialise
' Initialise UDP socket on first available port
udpSocket1.Initialize("UDP", 0, 8000)
' Initialse Map (Key=server uuid As String , Value=server details As UPNPserver)
serverID.Initialize
eotTimer.Initialize("EOT_Delay", 5000)
serverResponse = ""
End Sub
'Send a multicast message to search for devices of device type defined by 'st'
'mx - Maximum wait time in seconds
'st - Search target as defined by the UPNP device architecture
'
'Example: <code>
'M_Search(3, "ssdp:all")</code>
Private Sub M_Search(mx As Int, st As String)
' Compile HTTP broadcast message
Dim msg As String
msg = "M-SEARCH * HTTP/1.1~" & _
"HOST: 239.255.255.250:1900~" & _
"MAN: " & Chr(34) & "ssdp:discover" & Chr(34) & "~" & _
"MX: " & mx & "~" & _
"ST: " & st & "~~"
' Replace "~" with "\r\n" [NOTE:- CRLF only sends Chr(13) eg."\r"]
msg = msg.Replace("~", Chr(13) & Chr(10))
Debug.debugLog(msg) 'DEBUG
' Convert string to UTF8
Dim data() As Byte
data = msg.GetBytes("UTF8")
' Initialise packet and send
Dim packet As UDPPacket
packet.Initialize(data, "239.255.255.250", 1900)
udpSocket1.Send(packet)
End Sub
Private Sub UDP_PacketArrived (Packet As UDPPacket)
' Restart 1s timer each time a new packet arrives
EOT_Delay_Reset(1000)
' Convert received data to UTF8
serverResponse = BytesToString(Packet.Data, Packet.Offset, Packet.Length, "UTF8")
Debug.debugLog(CRLF & serverResponse) 'DEBUG
' Extract device uuid and description file url
Get_Details
End Sub
......
......