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