A call to Listen on the TRtcHttpServer object should trigger the "OnListenError" event if the Port is already in use, unless another Application has set the SO_REUSEADDR flag while opening their socket on that same Port, in which case you might NOT get errors (on some Windows versions) if you would try to Listen on that same Port, and the behavior of yours and any other Applications "listening" on that same port would be "indeterminate".
From what I can see, Microsoft has introduced a new flag in later Windows versions, which might resolve such problems (SO_EXCLUSIVEADDRUSE), but ... the RTC SDK does NOT have that flag declared, which means that you would have to add it yourself. If that is your intention, then you should open the
rtcWinSocket.pas unit from the RTC SDK (it should be in the "Lib" folder) and add the necessary flag in the
TRtcWinSocket.Listen method ... somewhere after the socket is created and before it is bound, which is currently in the code block following source code
line 1450 (you will see code setting other socket flags there). Adding the following lines of code there, should do the trick ...
optval := -1;
iStatus := _setsockopt(FHSocket, SOL_SOCKET, -5 {SO_EXCLUSIVEADDRUSE}, @optval, SizeOf(optval));
if iStatus <> 0 then
begin
RealSocketError('setsockopt(SO_EXCLUSIVEADDRUSE)',False);
Exit;
end;
SO_EXCLUSIVEADDRUSE is declared as -5 in .NET for C# and as (int)(~SO_REUSEADDR) in WinSock2.h (which is also -5, since SO_REUSEADDR is 4).
WARNING:
Administrator rights are (probably) required to set this option/flag.
See this MSDN article for more details about these flags and WinSock API behavior ...
https://learn.microsoft.com/en-us/windows/win32/winsock/using-so-reuseaddr-and-so-exclusiveaddruseBest Regards,
Danijel Tkalcec