Reading data received via UDP
Posted: Fri Oct 13, 2023 6:32 pm
I think I'm missing something really BASIC in trying to read a UDP message after a network event.
The loop that is supposed to be handling this:
It doesn't crash right away; it seems to happen when I suspect the UDP packet comes in and it does try to read the message from the buffer. I marked in the source where my trace shows the error (it's translating to an "Abort signal", error code 6, and I don't know if by that line number it means that parameter is where it is dying or the ReceiveNetworkData() call is the crash and it just flagged it at the last parameter.
Can someone offer some insight to what's going on here?
The loop that is supposed to be handling this:
Code: Select all
; Check for a UDP server event
LockMutex(mutNetUDPReference)
intEventNet = NetworkServerEvent(structNetUDPListener\intConnectionID)
intConnectionID = structNetUDPListener\intConnectionID
UnlockMutex(mutNetUDPReference)
If intEventNet = #PB_NetworkEvent_Data
Repeat
NetBuffer = AllocateMemory(#ConstantIncomingNetBufferSize)
intNetReadLen = ReceiveNetworkData(intConnectionID,
NetBuffer,
#ConstantIncomingNetBufferSize) ;; THIS IS THE LINE THAT APPEARS TO ERROR
strNetMessageReceived = strNetMessageReceived + PeekS(NetBuffer,
-1,
#PB_UTF8)
FreeMemory(NetBuffer)
Until intNetReadLen <> #ConstantIncomingNetBufferSize
;; DEBUG for now send this to debug
If CheckTreeEntries(intActiveMenuItem) = #TreeDebugWindow
AddGadgetItem(String_Debug_Receive_Box,
-1,
RTrim(strNetMessageReceived, #LF$))
strNetMessageReceived = ""
EndIf
EndIf
Can someone offer some insight to what's going on here?