Re: [twsocket] ICS send receive commands

2016-01-31 Thread ahmed hussein
sadly I want to practice on ics :) that's why I which to convert this code
from indy to ics to work same way , sadly AContext.Connection.Socket are
not similar in twsocket

On Wed, Jul 29, 2015 at 9:20 AM, Angus Robertson - Magenta Systems Ltd <
an...@magsys.co.uk> wrote:

> > 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
>
> Lots of the samples included with ICS sent simple text packets to each
> other, but
> I'd suggest you forget low level TWSocket and use my high level Magenta
> Systems IP
> Log Streaming Component that hides all this low level stuff and gives you
> a very
> simple interface to connect, send a line, receive a line, disconnect.
>
> http://www.magsys.co.uk/delphi/magics.asp
>
> There is an EXE demo that shows exactly what it does, and you should have
> a working
> application in an hour.
>
> 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
>
-- 
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