Solved

Connect several clients to one server

Posted on 2001-08-30
8
325 Views
Last Modified: 2010-04-06
Hello

I want to make a program that will be able to exchange data between one server and several clients using TCP/IP protocol. Now I have a program that use ServerSocket and ClientSocket to connect only 2 computers. I want to connect to server at least 5 computers, but it is impossible to use more than one ServerSocket in one program. Is somebody know how to connect several clients to one server ?

Thanks
0
Comment
Question by:Alexei
8 Comments
 
LVL 1

Expert Comment

by:SenDog
ID: 6443692
Try using the ICS Components from Francois Piette which are available at: http://overbyte.alexid.fr/frame_index.html

It has more functionality and allows multiple connections to TWsocketServer.
0
 
LVL 2

Expert Comment

by:PeterLarsen
ID: 6443902
Hi Alexei,

The following is a short explanation i have produced some time ago.

Hope this may help you !!

Use TClientSocket and TServerSocket - NonBlocking of cource.

The Client :

var
SendString : String:
Body : string;
MyErrorCode : integer;
....
SendString:='Something to send';
....
procedure xxx
begin
TClientSocket1.Open
Repeat
Application.Proccesmessage; //or run it in its own thread !!
until ContinueAfterPost:=true; //or something like this (e.g. a timeout)
end
...
procedure TFormClient.ClientWrite(Sender: TObject;
Socket: TCustomWinSocket);
begin
Socket.SendText(SendString);
end;
...
procedure TFormClient.ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
begin
Body:=Body+Socket.ReceiveText;
//
....
end;
...
procedure TFormClient.ClientError(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
MyErrorCode:=ErrorCode;
ErrorCode:=0;
ContinueAfterPost:=true;
end;
...
procedure TFormClient.ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
ContinueAfterPost:=true;
if MyErrorCode>0 then
exit; //There was an error
//
......
end;

The Server :

procedure TFormServer.ServerAccept(Sender: TObject;
Socket: TCustomWinSocket);
begin
You should create some kind of a record structure to save information about
this connection (all connections).
Socket has a data property (a pointer) in where you could save the record
pointer. You should also save the pointer in a TList.

It is then possible to run through the list to see whether a connection
should be timed out.
end;

procedure TFormServer.ServerClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
Check the body (received data) for valid data - or if there has been a
error.
end;

procedure TFormServer.ServerClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
MyRecord : ^TMyRecord;
begin
MyRecord:=Socket.Data;
MyRecord^.Body:=MyRecord^.Body+Socket.ReceiveText;
end;

Reply to client.
MyRecord^.SocketObject.SendText('a reply');

If your client is behind a proxy-server you must include a HTTP-header in
your stream.
This is a very very short explanation, but it's a beginning.


Regards
Peter
0
 

Expert Comment

by:grini
ID: 6444087
Hi,Alexei.
So,when a client connects to Server this generates
an OnclientConnect event and creates a new socket,
what you can use later:
Serversocket.Socket.connections[i]
The number of connections:
Serversocket.Socket.Activeconnections
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 1

Expert Comment

by:Dennis9
ID: 6448583
Hi.

You could put this on server sockets on read:
//
if ServerSocket1.Active then
  begin
    if ServerSocket1.Socket.ActiveConnections > 0 then
      for i := 0 to pred(ServerSocket1.Socket.ActiveConnections) do
        ServerSocket1.Socket.Connections[i].SendText('Text to send to all');
        edit6.clear;
end;
//

//Then it would look like this:
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
  Socket: TCustomWinSocket);
var
  i: integer;
  str: string;
begin
  str := Socket.ReceiveText;
  if ServerSocket1.Active then
  begin
    if ServerSocket1.Socket.ActiveConnections > 0 then
      for i := 0 to pred(ServerSocket1.Socket.ActiveConnections) do
        ServerSocket1.Socket.Connections[i].SendText(str);
  end
end;



Hope it helped.

Dennis
0
 
LVL 1

Expert Comment

by:venks
ID: 6466479
MIDAS is the  best answer for this.But  you require a license at each client
Venks
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 6485629
A ServerSocket can handle multiple connections at the same time. No need for Midas or other components, except if these provide other functionality which is essential to your application.
0
 

Expert Comment

by:loticom
ID: 7716115
I just cant understand why you need 2 ServerSockets ,1 would accomodate more than a single connection.

Or we didn't get your point?.
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 8280637
All,
I am unlocking this question in preparation for cleanup.  I will return in 7 days to finalize this question.  Please leave any recommendations for the final state of this question, I will take all recommendations into consideration.  Failing any feedback, I may decide in 7 days to delete or PAQ this question with no refund.  Thanks.

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
QRReport  TQrmemo vertical stretching 1 46
Tembedded WB animatid gifs not animated on some pcs 2 80
RESTRequest Parameter 4 31
Firemonkey allowing RTL on android 6 33
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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 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