TheGameCreators / AGK-Studio

3 stars 1 forks source link

[BUG] CreateUDPListener on occupied port does not fail as it should #1097

Open geezergamescybermind opened 1 year ago

geezergamescybermind commented 1 year ago

I can run two apps simultaneously that both use the same port with CreateUDPListener, neither will fail when creating the listener, but only one of them will actually receive data on that port. I have tested this with AGK Studio Tier 1 2023.01.25 Windows, and AGK Classic Tier 2 on Linux.

VirtualNomad19 commented 1 year ago

hey, @geezergamescybermind. a small snippet of code replicating the issue might help resolve.

geezergamescybermind commented 1 year ago

// Project: Test port // Created: 23-04-25

// show all errors

SetErrorMode(2)

// set window properties SetWindowTitle( "Test port" ) SetWindowSize( 1024, 768, 0 ) SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties SetVirtualResolution( 1024, 768 ) // doesn't have to match the window SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders UseNewDefaultFonts( 1 )

id1 = CreateUDPListener("anyip4", 7000) sleep(1000) sync() id2 = CreateUDPListener("anyip4", 7000)

do

timerStored = GetMilliseconds()

if timerStored > 10000
    DeleteUDPListener(id1)
    id1 = 0
endif

if id1 > 0

    if sendMessageToIdTimer < timerStored
        sendMessageToIdTimer = timerStored + 100
        messageID = CreateNetworkMessage()
        AddNetworkMessageInteger(messageID, timerStored)
        SendUDPNetworkMessage(id1, messageID, "127.0.0.1", 7000)
    endif

    messageForId1 = GetUDPNetworkMessage(id1)
    if messageForId1 > 0
        messageId1Int = GetNetworkMessageInteger(messageForId1)
        DeleteNetworkMessage(messageForId1)
    endif
endif

if id2 > 0

    if sendMessageToIdTimer < timerStored
        sendMessageToIdTimer = timerStored + 100
        messageID = CreateNetworkMessage()
        AddNetworkMessageInteger(messageID, timerStored)
        SendUDPNetworkMessage(id2, messageID, "127.0.0.1", 7000)
    endif

    messageForId2 = GetUDPNetworkMessage(id2)
    if messageForId2 > 0
        messageId2Int = GetNetworkMessageInteger(messageForId2)
        DeleteNetworkMessage(messageForId2)
    endif
endif

Print("Listener 1 ID:" + str(id1))
print("Listener 1 message integer:" + str(messageId1Int))
print(" ")
Print("Listener 2 ID:" + str(id2))
print("Listener 2 message integer:" + str(messageId2Int))
Sync()

loop

geezergamescybermind commented 1 year ago

This shows that ID2 only receives data after ID1 is closed and still gets an ID even though the port should be occupied.