سؤال

أنا أستخدم مكون Tserversocket في تطبيق Delphi الخاص بي. أود أن أقصر اتصالات العميل ، دعنا نقول لألف. لسوء الحظ ، لا أعرف كيف أفعل ذلك. لا يوفر المكون أي خصائص مثل "MaxConnections" أو أي مثل هذا واحد.

أقوم بإنشاء مؤشرات ترابط خادم جديدة (TserverClientThread) باستخدام حدث OnGetThread. للحصول على عدد الاتصالات النشطة ، استخدمت خاصية 'Socket.ActiveConnections'.

للأسف لا أعرف ماذا أفعل بعد ذلك. حاولت عدم إنشاء أي مؤشر ترابط داخل إجراء OnGetThread عندما يكون عدد الاتصالات أعلى من الحد ، لكنه لم يغير أي شيء - على الرغم من أنه غير قادر على إرسال أو استلام أي معلومات ، إلا أنه يمكنه الاتصال بالخادم والبقاء على اتصال. ما الذي لا يمكنك السماح للعملاء الجدد بالاتصال أو السماح لهم بالاتصال ولكن كسر الاتصال على الفور؟

هل كانت مفيدة؟

المحلول

Last time i used Delphi was some years ago, but i had a similar situation to deal with and my experience could be useful for you: i was facing the same problem and didn't want to switch to the "Indy" components since the (big) application wasn't worth the port. As far as i can remember, you should have an onClientConnect event on the server socket and here is were i checked for the limit:

.onClientConnect( Sender: TObject; aSocket: T... )
begin
    if( YourServerSocket.ActiveConnections > YourDefinedMaxConnections )
    begin
        // Drop the connection
        aSocket.Close;
    end;
end

I can't remember more other than that but i think i did something on these lines, or at least this was the thing i came up with.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top