Top.Mail.Ru
Мастера DELPHI, Delphi programming community Титульная страница Поиск, карта сайта Написать письмо 
| Новости | Поиск | FAQ | Статьи | Книги | Новости VCL |
| Форумы ЧАТ | Орешник | KOL и MCK |
Форумы -» Основная («Начинающим»)/ Базы / WinAPI / Компоненты / Сети / Media / Игры / Corba и COM / KOL / FreePascal / .Net / Прочее / RSDN.ORG

« предыдущая ветвь | форум | следующая ветвь »

? примеры использования TIdTCPClient и TIdTCPServer [D7, Win95/98, Win2k, WinXP]


Xlam ©   (2003-10-22 23:44:00) 

Подскажите плиз, где можно достать примеры использования
TIdTCPClient и TIdTCPServer или статейки.
Нужно написать прогу для передачи потоков, при чем клиенты время от времени будут запаршивать их, т е постоянно подключены и их нужно уведомлять об обновлениях этих самых потоков.


Александр из Минска   (2003-10-23 20:39:00) [1]

"C:\Program Files\Borland\Delphi6\Demos\Internet\Chat\Client"
"C:\Program Files\Borland\Delphi6\Demos\Internet\Chat\Server"
только то, что в этих папках!!! Это один целый проект!!! (правдо немножечко глюкавый, но там что касается передачи данных и т.д. все в норме)


BAPBAP   (2003-10-23 10:05:00) [2]

Сервер INDY:
program Project1;

uses
//Windows, Messages, Variants, Graphics, Controls, Forms,
//Dialogs, StdCtrls, OleCtrls, SHDocVw, IdBaseComponent, IdComponent,
Classes, SysUtils, IdTCPServer;

type
LohServer = class(TObject)
ServerType: TIdTCPServer;
constructor Create(Servername: TComponentName;
ServerPort: Integer);
destructor Destroy;
private
procedure OnConnect(AThread: TIdPeerThread);
procedure OnExecute(AThread: TIdPeerThread);
procedure OnDisconnect(AThread: TIdPeerThread);
public
end;

procedure LohServer.OnConnect(AThread: TIdPeerThread);
begin
//ShowMessage("Server Connected");
end;

constructor LohServer.Create(Servername: TComponentName;
ServerPort: Integer);
begin
ServerType:= TIdTCPServer.Create(nil);
ServerType.Name:= ServerName;
ServerType.DefaultPort:= ServerPort;
ServerType.Bindings.Clear;
ServerType.OnConnect:= OnConnect;
ServerType.OnDisconnect:= OnDisconnect;
ServerType.OnExecute:= OnExecute;
ServerType.Active:= True;
//ShowMessage("Server created");
end;

destructor LohServer.Destroy;
begin
//ShowMessage("Server is Destroyed");
ServerType.Free
end;

procedure LohServer.OnExecute(AThread: TIdPeerThread);
var
stream: TFileStream;
str: String;
begin
str:="16383"+#13+#10+"16383";
with AThread.Connection do
begin
WriteBuffer(Pointer(Str)^, Length(Str));
//WriteBuffer(PAnsiChar(str)^, Length(Str));
//WriteBuffer(Pointer(Buf[0])^, 5);
//WriteLn("Hello from Basic Indy Server server.");
Disconnect;
end;
end;

procedure LohServer.OnDisconnect(AThread: TIdPeerThread);
begin
//ShowMessage("Server Disconnected");
end;

var
MyServer:LohServer;
begin
MyServer:= LohServer.Create("Room1",5001);
try
//MyServer.ServerType.Active:=True;
while true do Sleep(5000);
finally
//MyServer.ServerType.Active:=False;
MyServer.Free;
end;
end.


BAPBAP   (2003-10-23 10:02:00) [3]

Клиент INDY:
program Project1;

uses
//Windows, Messages, Variants, Graphics, Controls, Forms,
//StdCtrls, OleCtrls, SHDocVw, IdBaseComponent, IdComponent,
//Dialogs,
Classes, SysUtils, IdTCPClient;

type
LohClient = class(TObject)
ClientType: TIdTCPClient;
constructor Create(Clientname: TComponentName;
ClientPort: Integer);
destructor Destroy;
private
procedure OnConnected(Sender: TObject);
procedure OnDisconnected(Sender: TObject);
public
end;

procedure LohClient.OnConnected(Sender: TObject);
begin
//ShowMessage("Client Connected");
end;

constructor LohClient.Create(Clientname: TComponentName;
ClientPort: Integer);
begin
ClientType:= TIdTCPClient.Create(nil);
ClientType.Name:= ClientName;
ClientType.Port:= ClientPort;
ClientType.Host:= "127.0.0.1";
//ClientType.ReadTimeout:= 0;
ClientType.OnConnected:= OnConnected;
ClientType.OnDisconnected:= OnDisconnected;
//ShowMessage("Client created");
end;

destructor LohClient.Destroy;
begin
//ShowMessage("Client is Destroyed");
ClientType.Free
end;

procedure LohClient.OnDisconnected(Sender: TObject);
begin
//ShowMessage("Client Disconnected");
end;

var
MyClient:LohClient;
a:ansistring;
begin
MyClient:= LohClient.Create("Room1",5001);
try
//MyClient.ClientType.Active:=True;
try
MyClient.ClientType.Connect;
except
MyClient.Free;
Halt;
end;
try
//a:=MyClient.ClientType.ReadLn;
a:=MyClient.ClientType.ReadString(10);
//ShowMessage(a);
finally
MyClient.ClientType.Disconnect;
end;
finally
//MyClient.ClientType.Active:=False;
MyClient.Free;
end;
end.


Reindeer Moss Eater   (2003-10-23 09:53:00) [4]

http://www.indyproject.org/indy/demodownloads/I9D6_Demos_24Nov02.zip


ilka   (2003-10-23 00:14:00) [5]

http://delphi.vitpc.com/table/search.asp


ilka   (2003-10-23 00:13:00) [6]

вернее "C:\Program Files\Borland\Delphi7\Demos\Indy\TCPStreamClientServer" а то еще не найдеш :)
Удачи...


ilka   (2003-10-23 00:12:00) [7]

"C:\Program Files\Borland\Delphi6\Demos\Indy\TCPStreamClientServer"


Наверх

Титульная страница Поиск, карта сайта Написать письмо