I'm not sure if you actually need to acquire and later release the multicast lock or if B4A or Android takes care of it for you. I've programmed a UPNP control point app and I've not needed to explicitly set the multicast lock but it seems to work.
Anyhow, if you really want to set the lock then maybe check out
this post here on the Forum which uses the reflection library to access it.
And just in-case your interested, this is the line I add to my manifest file...
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
And the broadcast and receive sections of code...
#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
......
......
Regards,
RandomCoder