I am sorry but INDY9 demos do not always work with 10 because of the restructuring and component redesign.., I have been there. My question is clear: I need to use Indy10 'NEW' idCMDTCPServer and idCMDTCPClient to send BINARY data, NOT Text wher I can use Oos Function. I also asked for WRKING example.
Here is a working example using subject components to send/receive clear text:
//*********************Sever
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdCustomTCPServer, IdTCPServer,
IdCmdTCPServer, StdCtrls, IdContext, IdUri, IdCommandHandlers;
type
TfrmMain = class(TForm)
OtaibiList: TListBox;
OtaibiServer: TIdCmdTCPServer;
procedure FormCreate(Sender: TObject);
procedure OtaibiServerConnect(AContext: TIdContext);
procedure OtaibiServerDisconnect(AContext: TIdContext);
procedure OtaibiServerCommandHandlers1Command(ASender: TIdCommand);
procedure OtaibiServerExecute(AContext: TIdContext);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
implementation
{$R *.dfm}
procedure TfrmMain.FormCreate(Sender: TObject);
begin
OtaibiServer.Active := True;
end;
procedure TfrmMain.OtaibiServerCommandHandlers1Command(ASender: TIdCommand);
begin
OtaibiList.Items.Add('Execute command from: ' +
ASender.Context.Connection.Socket.Binding.PeerIP);
ASender.SendReply;
ASender.Context.Connection.IOHandler.WriteLn('This is a dynamic response ' +
'from the Otaibi Server. It can be customized to add much ' +
'more functionality.');
end;
procedure TfrmMain.OtaibiServerConnect(AContext: TIdContext);
begin
OtaibiList.Items.Add('Connected from: ' +
AContext.Connection.Socket.Binding.PeerIP);
end;
procedure TfrmMain.OtaibiServerDisconnect(AContext: TIdContext);
begin
OtaibiList.Items.Add('Disconnected from: ' +
AContext.Connection.Socket.Binding.PeerIP);
end;
procedure TfrmMain.OtaibiServerExecute(AContext: TIdContext);
var
strCommand: string;
begin
strCommand := AContext.Connection.IOHandler.ReadLn;
if SameText (strCommand, 'text') then
AContext.Connection.IOHandler.WriteLn('200 OK');
end;
end.
//*********************Client
unit MainClient;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient;
type
TfrmMain = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
OtaibiClient: TIdTCPClient;
eHost: TEdit;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
implementation
{$R *.dfm}
procedure TfrmMain.Button1Click(Sender: TObject);
begin
If eHost.Text = '' then OtaibiCLient.Host := 'localhost'
else OtaibiClient.Host := eHost.Text;
OtaibiClient.Connect;
ShowMessage (OtaibiClient.IOHandler.ReadLn);
end;
procedure TfrmMain.Button2Click(Sender: TObject);
begin
OtaibiClient.Disconnect;
end;
procedure TfrmMain.Button3Click(Sender: TObject);
begin
OtaibiClient.SendCmd('test') ;
ShowMessage (OtaibiClient.LastCmdResult.Code + ' : ' +
OtaibiClient.LastCmdResult.Text.Text);
end;
procedure TfrmMain.Button4Click(Sender: TObject);
begin
OtaibiClient.SendCmd('execute') ;
ShowMessage (OtaibiClient.LastCmdResult.Code + ' : ' +
OtaibiClient.LastCmdResult.Text.Text);
ShowMessage (OtaibiClient.IOHandler.ReadLn);
end;
end.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137:





by: MaximKorobovPosted on 2008-06-01 at 06:09:59ID: 21686901
You can download INDY9 demos (which is also work with 10) from INDY site: kets/Demos /index.EN. aspx
CESSING</r equest>' and parse them on receiving (use Pos function).
http://indyproject.org/Soc
Look at "The 'old' Indy 9 demos" and folder IdTCPDemo inside the archive.
To work with many clients you should set MaxConnectionCount to your value (2+).
You can make specified data Class and send/receive them or send data like '<request>YOUR_DATA_TO_PRO