I think this is not the problem here: with limited resources, one might expect failed connections, slow responses, etc., but a StackOverflowException doesn’t make sense and clearly seems like a bug to me. The fact that this doesn’t happen on macOS (at least in my testing) also points to it being a bug.
The ServerSocket manages a pool of TCPSockets that are set to the listen state.
The ServerSocket.AddSocket event is where you create the TCPSockets that ServerSocket sets to listen.
Callling ServerSocket.Listen causes ServerSocket.AddSocket to be called 10 + ServerSocket.MinimumSocketsAvailable times.
When a client connects the socket it connects to transitions from the listen state to the connected state and is no longer available to the listening pool.
Each time ServerSocket accepts a new client connection the listening pool is depleted by 1.
When the number of sockets in the listening pool falls below MinimumSocketsAvailable, AddSocket is again called 10 + MinimumSocketsAvailable times to replenish the listening pool.
MaximumSocketsConnected is the maximum number of sockets ServerSocket allows to be in the connected state simultaneously.
If MaximumConnectedSockets is set to 4 and 4 clients have connected and no clients have disconnected, ServerSocket will reject the next client that attempts to connect, although there are at least 6 sockets left in the listening pool.
When a client disconnects, the number of connected sockets falls below MaximumSocketsConnected and ServerSocket will accept a new connection.
SUB TCPSocket.DataAvailable()
static isActive as boolean = False
if isActive then return
isActive = True
app.arrayDati.Add(me.ReadAll)
me.Write("reply")
isActive = False
END
with this variant I have the same problem (I have the problem even if there is no code in the available data)
SUB TCPSocket.DataAvailable()
static isActive as boolean = False
if isActive then return
isActive = True
app.arrayDati.Add(me.ReadAll)
me.Write("reply")
isActive = False
END
a clarification for those who want to reproduce the problem, the exception is raised much earlier if there are 4 or 5 clients calling the server
and the stack exception is thrown even before and exactly at the time the clients try to create connections!!! even worse, we are not even in the transmission phase, an even bigger problem because it exposes the server to a DOS attack!!
i not get that stack exeption. (i used Xojo 2024r1.1 started from ide)
have you also add Super.Constructor in the skAscolto Constructor in Server Project?
i opened 5 compiled client exe and start one by one.
then i have change the number of requested connection from client to 3000
using client modified from MarkusR that estabilish connetion with a time and not with for next cycle
If SocketObjectCount < 3000 Then
NewConnection
SocketObjectCount=SocketObjectCount+1
End If
and with only one client the server generate exception in connectted event when client try to make connections
if there was only a buffering in the DataAvailable event as @Greg_O tried to suggest you may get away without the exception.
(i do think xojo must fix it somehow, but we need to find the cause first).
It could be that the DataAvailable is called prematurely again and again instead of the other stuff happening.
it can be anything,
the big problem is that these errors cannot be intercepted and therefore cannot be managed by code and this can generate the loss of the data received