Hi all, I'm trying to send a UDP broadcast on the local network in order to discover my server. I wrote a udp client/server in c, and it works. Now, I'm trying to convert the client to brighscript, but I can't get it working. It seems that the server never receives any packets. Right now I've stripped the code down to just
sending the packet. I then watch the server output to see if the packet is received -- it never is.
Here's the code I'm using:
function Discover()
SEND_PORT = "8881"
KEY_SEND = "SeCrEt"
msgPort = CreateObject("roMessagePort")
sendSock = CreateObject("roDatagramSocket")
sendSock.SetMessagePort(msgPort)
sendAddr = CreateObject("roSocketAddress")
sendAddr.setAddress("255.255.255.255:"+SEND_PORT)
sendSock.setSendToAddress(sendAddr)
sendSock.setBroadcast(true)
sendSock.notifyReadable(true)
data = CreateObject("roByteArray")
data.FromAsciiString(KEY_SEND)
' Sanity Check
?"Data count: "+data.Count().tostr()
sendSock.send(data, 0, data.Count())
' Check error
if sendSock.eAgain()
?"E_AGAIN"
return false
else if sendSock.eAlready()
?"E_ALREADY"
return false
else if sendSock.eDestAddrReq()
?"E_DEST_ADDR_REQ"
return false
else if sendSock.eHostUnreach()
?"E_HOST_UNREACH"
return false
else if sendSock.eInProgress()
?"E_IN_PROGRESS"
return false
else if sendSock.eOk()
?"E_OK"
else if sendSock.eSuccess()
?"E_SUCCESS"
else if sendSock.eWouldBlock()
?"E_WOULD_BLOCK"
return false
end if
continue:
while true
event = wait(1000, msgPort)
if event = invalid
?"Recevieved invalid event"
goto continue
end if
if type(event) <> "roSocketEvent"
?"Received unknown type"
goto continue
end if
?"Message: " + event.GetMessage()
end while
end function
Can anyone see the problem? Any help would be greatly appreciated. Cheers!