Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Server "connection" object/variable when disconnecting from server side
#1
Hello,

I intend to build a TCP server able to serve lots of clients. Because of the port depletion in Windows (and for some other reasons), I use disconnect from the server side, not from the client side.

The steps are like this: client connects, client requests data, server answers with data, client requests disconnect, server disconnects.

The OnExecute in server does not process the requests, but it adds them to a queue, from which they are retrieved almost immediately by the queue processing thread, and then processed in 4 - 64 parallel task/job processing threads.

The problem I encountered is that many times (not always, but quite frequently) the "connection" object I saved from within the OnExecute (AContext.Connection) and stored into the queue is no longer the same when the task or job is retrieved from the queue. The connection object now points to a different connection, that may have been already closed. This leads to sending data to the wrong client, or using disconnected connections, or to more exceptions because the Sockets, IOHandlers and so on are already freed.

I tried to find the right connection in the Server.Contexts but the problem of course persists, because other threads are concurrently disconnecting from the server side, and until the newly found connection variable is used, it may not be the same as the one retrieved three lines of code above, or 20 milliseconds before.

How can I save from within OnExecute a persistent "connection" that can be used even seconds later, outside the OnExecute event, if the disconnections occur on the server side and not on the client side?

Thank you
Reply


Messages In This Thread
Server "connection" object/variable when disconnecting from server side - by noname007 - 10-28-2020, 10:14 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)