Solved

TServerSocket

Posted on 2001-08-28
3
264 Views
Last Modified: 2010-04-06
So, I have a serversocket and I want that no more than N(e.g. N=3) clients to be able to connect to this.
How can I do it?
0
Comment
Question by:grini
3 Comments
 
LVL 3

Accepted Solution

by:
Pegasus100397 earned 20 total points
ID: 6432437
Grini,

 In your OnConnect event, get the ServerSocket.Connection.Count and check to see if its over 3. If it is then issue a disconnect to the 4th socket.

Good luck with your project!
Pegasus
0
 
LVL 1

Expert Comment

by:Dennis9
ID: 6434049
Hi.
u can do that like this:
if (ServerSocket.Connection.Count = 3) or (ServerSocket.Connection.Count > 3) then ...//some code to not let more people in


Dennis
0
 
LVL 2

Expert Comment

by:alsantos
ID: 6434756
grini, use this example:

{ var global }
var
  total: integer;

...

procedure TForm1.FormActivate(Sender: TObject);
begin
total:=0;
end;

procedure TForm1.ServerSocket1ClientConnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
inc(total);
if total > 3 then begin
  socket.Disconnect(total);
  socket.SendText('Error. 3 connections already active.');
 end
else begin
  socket.Accept(total);
  socket.SendText('Connected.');
end
end;

procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
dec(total);
end;


Alexandre Santos
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question