[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Connect several clients to one server

Posted on 2001-08-30
8
Medium Priority
?
389 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

649 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