Solved

Connect several clients to one server

Posted on 2001-08-30
8
333 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

732 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