Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [BUG] Two apps on same device using UDP listener not possible

Author
Message
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 14th May 2019 14:09
I might have found a bug. I have a Tier 2 Linux console app that uses UDP listeners. The first app is running just fine but the second instance of the app reports "Failed to bind listening socket". I have tried hard-coding two different ports for the two apps to use, but that doesn't help. I have code that should check for whether the CreateUDPListener returns 0 or a connection ID, then increment port if it returns 0, but it always gives me a connection ID, even though the port is in use by the other app instance.
13/0
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 16th May 2019 14:50
Here is a small test, an app with a hardcoded port, running two isntances lets me bind a second UDP listener to the same port.

13/0
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 16th May 2019 19:45
Furthermore, creating two UDP listeners on the same port in the same app just gives me two IDs, it doesn't complain that there is already a listener on the same port.

13/0
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 1st Jun 2019 19:58 Edited at: 1st Jun 2019 19:58
Did anybody try this? Here is a small piece of Tier 1 code that lets me create 6 listeners on the same port, none of them complains and gives me an ID for each when they should fail (or at least the 5 last listeners should).

13/0
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 1st Jun 2019 21:12
Hey,

code works without any errors on both AGK2 and AGKS!

Output:
100001
100002
100003
100001
100002
100003


PSY LABS Games
Coders don't die, they just gosub without return
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 3rd Jun 2019 12:17
The problem is, only the first listener should return an ID, the rest should return zero because they use the same port.
13/0
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 3rd Jun 2019 13:55 Edited at: 3rd Jun 2019 13:57
Internally the socket creation for UDP uses an argument called SO_REUSEADDR. This is used on both the windows and linux versions of AGK. (if you want exclusive access you would use SO_EXCLUSIVEADDRUSE)

What that essentially means is that the socket CAN have multiple listeners bound to it. Typically that is to allow multicasting using UDP to multiple apps on one machine which can be quite useful.

Quote: "Only one usage of each socket address (protocol/network address/port) is normally permitted.
An error is returned if a process on the computer is already bound to the same fully qualified address and the socket has not been marked to allow address reuse with SO_REUSEADDR. For example, the IP address and port specified in the name parameter are already bound to another socket being used by another application. For more information, see the SO_REUSEADDR socket option in the SOL_SOCKET Socket Options reference, Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE."


I suppose that makes the documentation somewhat incorrect which does state that if the port is used then it will return 0 - except that it doesn't and will succeed depending on the OS's implementation of the sockets API it uses.
https://www.appgamekit.com/documentation/Reference/Multiplayer/CreateUDPListener.htm

So...not sure its a bug or...incorrect documentation ??
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 3rd Jun 2019 14:27 Edited at: 3rd Jun 2019 14:27
Oh, I see, I went by what the documentation said. Then it would be nice if there was an option to ask for exclusive use when binding a listener to a port.
13/0
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 6th Jun 2019 13:39
I've been looking for WindowsNetwork.cpp but can't find it That should be the file with this option you mentioned Bengismo. I can find all the headers, but not the cpp files.
13/0
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 6th Jun 2019 14:08 Edited at: 6th Jun 2019 14:14
See Line numbers: 346, in WindowsNetwork.cpp
https://github.com/TheGameCreators/AGKTier2/blob/master/platform/windows/Source/WindowsNetwork.cpp

Its similar on the linux and android sources too (except different line numbers):
https://github.com/TheGameCreators/AGKTier2/blob/master/platform/linux/Source/LinuxNetwork.cpp

Search for SO_REUSEADDR in any of the platform source network files

Basically the UDP manager always allows address reuse. If your using Teir 2 then you could disable it if you really want to only ever have one connection.
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 7th Jun 2019 19:05
Oh, I have to download the source from Github I thought the source should be somewhere in my install Thanks!
13/0
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 13th Jun 2019 08:53
Hi again I am having trouble compiling the source, it says that Xaudio2.h is missing, I've tried using NuGet to install directx_2015 and other versions, I've tried downloading DirectX SDK but can't figure out how to get that included in the compiling. Do you know how to get the Xaudio2 header included?
13/0

Login to post a reply

Server time is: 2024-11-22 21:40:03
Your offset time is: 2024-11-22 21:40:03