Socket Connectivity

I have a D5 application where multiple clients use ClientSockets to maintain a dialogue with a server using a ServerSocket.  When the Server application starts up the first time and then clients start up, communication works OK. If I close a client down and then start the same client again, communication between that client and the server is not restored.  It seems that I have to write some code in the OnClientDisconnect event for the ServerSocket to overcome this.
Has anyone got a solution
anthonyfauntAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

keithcslCommented:
anthonyfaunt

strange. i don't seem to be getting that error. i can close and reconnect the client without any problems.

maybe u might want to post a code snippet...

Keith
0
anthonyfauntAuthor Commented:
Hi Keith,

I have atttached relevant code in both applications (Server application & Client application)

Server Application

procedure TFormMain.ServerSocket1ClientConnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  StatusBar1.Panels[4].Text :=
   IntToStr(ServerSocket1.socket.ActiveConnections) + ' Connections';
end;

procedure TFormMain.ServerSocket1ClientDisconnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  StatusBar1.Panels[4].Text := IntToStr(ServerSocket1.socket.ActiveConnections) + ' Connections';
end;

Client Application

On startup the Client Application executes the following code:

 (IPAddress picked up from an ini file)
  with ClientSocket1
  do
  begin
    active := false;
    address := IPAddress;
    clientType := ctNonBlocking;
    port := 50;
    active := true;
  end;

  StatusBar1.Panels[4].Text :=
   'Connecting to '
    + Clientsocket1.address;

Other code related to ClientSocket1 is superficial:

procedure TFormMain.ClientSocket1Connect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  StatusBar1.Panels[4].Text := 'Connected to '+
  socket.remotehost + ' ['+
  socket.remoteaddress + ']';
end;

procedure TFormMain.ClientSocket1Disconnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  Application.Terminate;
end;

When the client shuts down, StatusBar1.Panels[4].Text (on the Server Application) remains as '1 connections'

Tony,

PS I notice you are in NZ.  I'm not far away in Canberra Aus.

0
keithcslCommented:
Hi Tony

In the OnDisconnect, you have called Applicaiton.Terminate. This might cause a poor disconnect in the socket. I suspect it will work if you remove the Application.Terminate.

PS: I am watching the FIFA under 17 between Aus and Brazil at the moment.

Keith
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

anthonyfauntAuthor Commented:
Hi Keith,

My intention with the Application.Terminate call is to shut down Clients if the Server shuts down.  There can be a number of clients connected to the one server and all clients depend on the Server running.
Is this the wrong logic?

Tony

PS I'm sure Aus will win - just like in the recent Rugby World Cup.
0
keithcslCommented:
anthonyfaunt

Try Close instead. That will ensure a proper termination.

PS: That was the most nail biting match i have ever seen!!! I'd better not broadcast the score here... might get hate mails... :)

Keith
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RadlerCommented:
Hi keithcsl;

Congratulations to Brazil !
We make good players and bad politics.

T++, Radler.
0
anthonyfauntAuthor Commented:
Keith,

Sorry for the delay in responding - I have not got back to you because of pressure of work.  My present project is a re-write of the Canberra City Ambulance Dispatch System and it goes live today.  Your advice seems to have fixed the problem in that clients can now shut down and reconnect with no problems.  Thanks a million for your advice.

Tony

PS: I watched the replay of the match against Brazil and agree it was an exciting finish.  I was pleased to watch the third cricket test against Pakistan in which the result was as it should have been (only kidding).
0
anthonyfauntAuthor Commented:
Frankly, I don't understand the difference between Application.Terminate and Close but obviously you do Keith.
0
keithcslCommented:
anthonyfaunt

i have not gone through the details of Application.Terminate, but i know that it should not be used to close a program. I use it only for exceptions, eg if a file a corrupted, a dll is not found, etc and my program cannot carry on further.

From experimentation, Application.Terminate forces the program to close, and most of the Windows Messages in the queue get discarded. On the contrary, Close behaves like the user has clicked in the X button. This means all pending messages are processed.

PS: are u a programmer in the data communications field? ie data dispatch, MDTs, etc. i am doing a similar thing, only in that i am specialising in the taxi industry.

Keith
0
anthonyfauntAuthor Commented:
Keith,
Thanks for the further info re Application.Terminate & Close.
The Canberra Ambulance System has not gone to MDTs as yet.  They still use 6 tone radio signalling to record their progress around case deplopyment and still receive case data by voice radio.  Up until now the system had used Paradox tables but I have just migrated it into a 3 tier system using MSSQL 7.
I use sockets to keep all screens in the control centre synchonised.
TOny
 
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.