Re: [twsocket] How to keep SslWSocket open in a multi-threaded console app?

2015-07-29 Thread Paul Read - nSolve Ltd
Thanks Angus, in fact I likewise I have a simple switch at startup to 
decide whether I'm running in GUI or service mode, which I share below 
as a way of saying thanks to the 'list' as I did not take on-board the 
fact that the Svcmgr::Application-CreateForm call means the TService 
class is dervived from TObject item and that can have a TSslWSocket 
component on it without any manual message pumps (rather than creating a 
thread that then creates the SslWSocket):


//---
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
if(FindCmdLineSwitch(GUI))
{
Forms::Application-Initialize();
Forms::Application-CreateForm(__classid(TfrmMain), frmMain);   
//(TfrmMain::OnShow then creates the TService based object

Forms::Application-Run();
}
else
{
if((!Svcmgr::Application-DelayInitialize) || 
(Svcmgr::Application-Installing()))

{
Svcmgr::Application-Initialize();
}
Svcmgr::Application-CreateForm(__classid(some class dervived from 
TService), pService);

 Svcmgr::Application-Run();
}
}


Thanks to all


--
Regards

Paul Read
Partner

Follow us: @nSolve http://www.twitter.com/nSolve

*nSolve Ltd*
33-35 Daws Lane
London NW7 4SD
England

www.nsolve.com http://www.nsolve.com

Tel: +44 (0) 1993 40 20 11
Tel(US): +1 617 273 2304


On 29/07/2015 08:15, Angus Robertson - Magenta Systems Ltd wrote:

Should I be calling MessageLoop or ProcessMessages?

Neither, Delphi windows services are message driven just like Windows 
applications.
Most of my windows services are actually dual GUI/service, with a simple GUI 
that
does not require any interaction when run as a service.  This makes testing 
vastly
easier, since the program can be run under the Delphi debugger and then 
installed as
a Windows service once it's working.

Originally I wrote a simple service starter application that runs a standard 
Windows
application as a service (with a command argument) and waits for it to finish 
before
stopping, and sends a message if told to stop.  I still sell an application 
using
this technique after 18 years.

The second generation used the SvCom environment from:

http://www.aldynsoftware.com/

which creates a single application that can be run as a service or GUI, just 
drop
components on a form, jkust works, but it's commercial.

For new applications I use DD Service Application Framework written by one of 
the
ICS developers, but his web site seems to be down at the moment.  I think it's 
on
Code Central but search is useless and brings up thousands of results.

Angus



--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] How to keep SslWSocket open in a multi-threaded console app?

2015-07-29 Thread Wilfried Mestdagh

Hi,

I do it a little different but results are similar. I create my whole 
application in a single TObject. So this object can run in a GUI as a 
console application as a NTService.


For console application just App.Create; and run a message pump, for 
NTService the same: create the object and run message pump.


So whole debugging and testing is in the console application (or GUI as 
you wish) - if all is running OK, just recomile the Service and it's 
done. There is even no testing required with the Service because it is 
exacly the same object that is running.


Met vriendelijke groeten,
Wilfried

Op 29-07-15 om 09:15 schreef Angus Robertson - Magenta Systems Ltd:

Should I be calling MessageLoop or ProcessMessages?

Neither, Delphi windows services are message driven just like Windows 
applications.
Most of my windows services are actually dual GUI/service, with a simple GUI 
that
does not require any interaction when run as a service.  This makes testing 
vastly
easier, since the program can be run under the Delphi debugger and then 
installed as
a Windows service once it's working.

Originally I wrote a simple service starter application that runs a standard 
Windows
application as a service (with a command argument) and waits for it to finish 
before
stopping, and sends a message if told to stop.  I still sell an application 
using
this technique after 18 years.

The second generation used the SvCom environment from:

http://www.aldynsoftware.com/

which creates a single application that can be run as a service or GUI, just 
drop
components on a form, jkust works, but it's commercial.

For new applications I use DD Service Application Framework written by one of 
the
ICS developers, but his web site seems to be down at the moment.  I think it's 
on
Code Central but search is useless and brings up thousands of results.

Angus



--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] How to keep SslWSocket open in a multi-threaded console app?

2015-07-29 Thread Angus Robertson - Magenta Systems Ltd
 Should I be calling MessageLoop or ProcessMessages?

Neither, Delphi windows services are message driven just like Windows 
applications.
Most of my windows services are actually dual GUI/service, with a simple GUI 
that
does not require any interaction when run as a service.  This makes testing 
vastly
easier, since the program can be run under the Delphi debugger and then 
installed as
a Windows service once it's working. 

Originally I wrote a simple service starter application that runs a standard 
Windows
application as a service (with a command argument) and waits for it to finish 
before
stopping, and sends a message if told to stop.  I still sell an application 
using
this technique after 18 years.   

The second generation used the SvCom environment from: 

http://www.aldynsoftware.com/

which creates a single application that can be run as a service or GUI, just 
drop
components on a form, jkust works, but it's commercial.

For new applications I use DD Service Application Framework written by one of 
the
ICS developers, but his web site seems to be down at the moment.  I think it's 
on
Code Central but search is useless and brings up thousands of results.

Angus

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


[twsocket] ICS send receive commands

2015-07-29 Thread ahmed hussein
iam using ics TWSocket  TWsocketserver , I been using indy tcp before ,
and I asked about how to convert my code in indy to be used in ics and the
creator suggested me to use mailing list

this is my question


http://stackoverflow.com/questions/31640329/convert-indy-protocol-to-ics


I just wanted to know how to create similar protocol in ics and send
commands based on its reference

as example send command from client

Delphi CODE

sendcommand(Socket, 'showmessage', message + lineEnd , anothermessage +
lineEND);

I been doing this in indy like that


procedure TServer.SendCommandParams(Connection: TConnection; Command,
Params:String);var
  PackedParams: TPackedParams;begin
  if not TIdContext(Connection.Thread).Connection.Socket.Connected then
Exit;
  TCPServer.Contexts.LockList;
  try
PackedParams.Params := ShortString(Params);
with TIdContext(Connection.Thread).Connection.Socket do
begin
  WriteLn('1' + Command);
  Write(RawToBytes(PackedParams, SizeOf(PackedParams)));
end;
  finally
TCPServer.Contexts.UnlockList;
  end;end;



---



procedure TServer.BroadCastTextMessage(const TextMessage: String;
const id: DWord);var
  I: Integer;
  Connection: TConnection;begin
  for I := 0 to Connections.Count - 1 do
  begin
Connection := Connections.Items[I];
if Connection.id  id then
  SendCommandParams(Connection, 'TEXTMESSAGE', TextMessage + Sep);
  end;end;



--




procedure Tserver.TCPServerExecute(AContext: TIdContext);var
  Connection: TConnection;
  Command: String;
  Params: array[1..10] of String;
  ParamsCount, P: Integer;
  PackedParams: TPackedParams;
  IdBytes: TIdBytes;
  MS: TMemoryStream;
  ReceiveParams, ReceiveStream: Boolean;
  Size: Int64;begin
  Connection := Pointer(AContext.Data);
  MS := TMemoryStream.Create;
  ReceiveParams := False;
  ReceiveStream := False;
  Command := AContext.Connection.Socket.ReadLn; //read command

  if Command[1] = '1'  then //command with params
  begin
Command := Copy(Command, 2, Length(Command));
ReceiveParams := True;
  end
  else if Command[1] = '2' then //command + memorystream
  begin
Command := Copy(Command, 2, Length(Command));
ReceiveStream := True;
MS.Position := 0;
  end
  else if Command[1] = '3' then //command with params + memorystream
  begin
Command := Copy(Command, 2, Length(Command));
ReceiveParams := True;
ReceiveStream := True;
  end;

  if ReceiveParams then //params is incomming
  begin
AContext.Connection.Socket.ReadBytes(IdBytes, SizeOf(PackedParams), False);
BytesToRaw(IdBytes, PackedParams, SizeOf(PackedParams));
ParamsCount := 0;
repeat
  Inc(ParamsCount);
  p := Pos(Sep, String(PackedParams.Params));
  Params[ParamsCount] := Copy(String(PackedParams.Params), 1, P - 1);
  Delete(PackedParams.Params, 1, P + 4);
until PackedParams.Params = '';
  end;
  if ReceiveStream then //stream is incomming
  begin
Size := AContext.Connection.Socket.ReadInt64;
AContext.Connection.Socket.ReadStream(MS, Size, False);
MS.Position := 0;
  end;


  if Command = 'TEXTMESSAGE' then
  begin
BroadCastTextMessage(Params[1], Connection.id);
  end;

  MS.Free;end;


---



const
  Sep = '#$%^';
  DefaultPort = 1555;
type
  TPackedParams = packed record
 Params: string[250];
  end;



---



*can I do the same approach in ics ? if yes is there example about this ?*
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be