TIdTCPServer reconnection for the same login user

My server build on TIdTCPServer should be capable for only one single connection for one user at the same time. I searched a lot but I can't find resolve.

Everything looks correct if there are no errors, I mean: at the begining client sends login and password, methods onconnect or onexecute check are they ok and user connection with the same name dosen't exist. If everything is ok than exchanging of messages is starting. If not, method fo disconnection is calling.

But, when such a remote application (written using other tools than Indy) unintentionally lose the connection (due to temporary loss of network) server does not know about this immediatly and thinks that everything is ok. At the same time the client application already knows there was an error. When network connection is good again, client application attempts to connect to the server but the attempt is rejected (by server) because the server keep last connection from this user (until a certain time when connection is close on error event).

Is there a way of bypassing the problem of rejection after a quick resuming connection without rejecting two (last and actual attempted connection from the same client to clear information about loged user) to give him possibility until the next attept?

I use the trick with "heartbeat" for checking connection but in 10seconds interval because of huge number of clients and cost of transfer - clients use paid gprs connection. And in this time my client application sometimes has problem with reconnection.

There is other problem. When the first connection form user is ok and he is trying connect from other application with the same name of user only the second connection has to be rejected.


If a client attempts to login with a username/password that is already "connected", you have only two choices:

  1. reject the new connection and keep using the previous connection until it disconnects (if it times out, disconnect it).

  2. disconnect the previous connection immediately and use the new connection.

Whichever one you decide to use depends on your particular needs.

You are currently doing #1, but it sounds like you probably need to use #2 instead. However, your requirement that "When the first connection form user is ok and he is trying connect from other application with the same name of user only the second connection has to be rejected." requires #1 and prevents #2. So you are kind of in a catch-22 situation. There is no way for the server to know whether a client is abnormally disconnected on the client end, it has to use keepalives/heartbeats to detect that. You cannot rely on the server socket telling you the client is dead in a timely manner because it has to time out internally first, and that can take a long time without keepalives enabled.

Need Your Help

Formatting .NET TimeSpan in unityscript

.net datetime unity3d unityscript

I'm trying to format a .NET TimeSpan in Unity with unityscript.

How to extract xml string to make a new colums in sql using XQuery/XPath?

sql xml xpath xquery extract

Hi I have here my code for now and Im not getting the result correctly using this codes;

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.