Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Porting old Delphi2007 application using TServerSocket....
#2
Never mind, I finally found a useful webpage with some description on how to implement the simple client/server connection.

My needs are really not very complex, I need to implement a TCP server class that can accept connections and which will transfer incoming data to an already existing handler.

The handler will output some data to be sent back to the client so this TCP "relayer" must have a function which will transfer the data back o the client. Or a processing function returning the response to send back.
No data will ever be sent to the client without a prior request.

What I would like to know is if the TIdTCPServer object will trigger the OnExecute event when data arrive from the connected client?

Is there something one has to do in order for that to happen, like defining message delimiters?

The example I cut code from uses OnExecute to retrieve and process client data, but I seem not to get any extraction here...

Right now my OnExecute looks like this (ProcessRequest is a placeholder for a function that will take the client message payload and do whatever needed and then create a response to send back):

Code:
procedure TRemoteServer.ServerExecute(AContext: TIdContext);
var
  msg, reply: string;
begin
  // ... get incoming message from client and supply it to the consumer
  msg := AContext.Connection.IOHandler.ReadLn;
  // Right now just print to stdout
  writeln(msg);
  reply := ProcessRequest(msg);
  AContext.Connection.IOHandler.WriteLn(reply);
end;

The test client I have will send a login message following connection and it looks like this:

<STX>USER=username<CR>PWD=password<ETX>

So it is delimited using <STX> and <ETX> and the payload between these can be any normal ASCII characters incluting <CR>, <LF>, <TAB> etc.

All messages are delimited this way, so I would need something that can read incoming data up until the <ETX> char arrives, and then process them.

In the example IOHandler.Readln/IOHandler.Writeln is used and that is probably incorrect.

In my tests right now I will only write out the incoming data to STDOUT for checking.

So how can I get the content of the delimited message from the client in OnExecute?
Reply


Messages In This Thread
RE: Porting old Delphi2007 application using TServerSocket.... - by BosseB - 07-06-2020, 02:29 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)