Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2004.09.12;
Скачать: CL | DM;

Вниз

idTCPServer и idTCPClient как обмениваться сообщениями ?   Найти похожие ветки 

 
banderas   (2004-07-03 19:33) [0]

Как с помощью idTCPServer и idTCPClient передовать сообщения


 
Winni   (2004-07-04 13:18) [1]

Пример есть в комплекте Delphi6 (и Delphi7): Delphi6\Demos\Internet\Chat здесь есть папки Client и Server. Все работает.


 
banderas   (2004-07-04 14:42) [2]

Нее там используется не idTCPServer и idTCPClient а просто  TCPServer и TCPClient которые не являются компонентами indy


 
Winni   (2004-07-04 22:15) [3]

{***************************************************************
*
* Project  : CBClient
* Unit Name: MainForm
* Purpose  :
* Version  : 1.0
* Date  : Wed 25 Apr 2001  -  01:12:33
* Author  :
* History  :
* Tested  : Wed 25 Apr 2001  // Allen O"Neill <allen_oneill@hotmail.com>
*
****************************************************************}

unit MainForm;

interface

uses
{$IFDEF Linux}
  QGraphics,  QControls,  QForms,  QDialogs,  QComCtrls,  QMenus,  QButtons,
    QExtCtrls,  QStdCtrls,
{$ELSE}
  Graphics,  Controls,  Forms,  Dialogs,  ComCtrls,  Menus,  Buttons,  ExtCtrls,
    StdCtrls,
{$ENDIF}
 windows, messages,  ToolWin, spin,  SysUtils,  Classes, IdBaseComponent,
   IdComponent, IdTCPConnection, IdTCPClient;

type
 TForm1 = class(TForm)
   Label1: TLabel;
   edUserName: TEdit;
   Label2: TLabel;
   edServer: TEdit;
   Label3: TLabel;
   lbClients: TListBox;
   Label4: TLabel;
   memLines: TMemo;
   Label5: TLabel;
   edMessage: TEdit;
   SpeedButton1: TSpeedButton;
   IdTCPClient1: TIdTCPClient;
   Timer1: TTimer;
   Label6: TLabel;
   sePort: TSpinEdit;
   Button1: TButton;
   procedure FormShow(Sender: TObject);
   procedure Timer1Timer(Sender: TObject);
   procedure SpeedButton1Click(Sender: TObject);
   procedure IdTCPClient1Connected(Sender: TObject);
   procedure edMessageKeyPress(Sender: TObject; var Key: Char);
   procedure Button1Click(Sender: TObject);
 private
   { Private declarations }
 public
   { Public declarations }
 end;

var
 Form1: TForm1;

implementation

{$IFDEF MSWINDOWS}{$R *.dfm}{$ELSE}{$R *.xfm}{$ENDIF}

procedure TForm1.FormShow(Sender: TObject);
begin
 width := width + 1;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
 Com,
   Msg: string;
begin
 if not IdTcpClient1.Connected then
   exit;

 Msg := IdTCPClient1.ReadLn("", 5);

 if Msg <> "" then
   if Msg[1] <> "@" then
   begin
     { Not a system command }
     memLines.Lines.Add(Msg);
   end
   else
   begin
     { System command }
     Com := UpperCase(Trim(Copy(Msg, 2, Pos(":", Msg) - 2)));
     Msg := UpperCase(Trim(Copy(Msg, Pos(":", Msg) + 1, Length(Msg))));
     if Com = "CLIENTS" then
       lbClients.Items.CommaText := Msg;
   end;

end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
 if (edUserName.Text <> "") and
   (edServer.Text <> "") and
   SpeedButton1.Down then
 begin
   IdTCPClient1.Host := edServer.Text;
   IdTCPClient1.Port := sePort.Value;
   if SpeedButton1.Down then
     IdTCPClient1.Connect;
 end
 else
 begin
   if (edUserName.Text = "") or
     (edServer.Text = "") then
     ShowMessage("You must put in a User Name and server name to connect.");
   SpeedButton1.Down := false;
 end;
end;

procedure TForm1.IdTCPClient1Connected(Sender: TObject);
begin
 IdTCPClient1.WriteLn(edUserName.Text);
end;

procedure TForm1.edMessageKeyPress(Sender: TObject; var Key: Char);
begin
 if key = #13 then
 begin
   IdTCPClient1.WriteLn(edMessage.Text);
   edMessage.Text := "";
 end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 IdTCPClient1.WriteLn("@" + "CLIENTS:REQUEST");
end;

end.


 
banderas   (2004-07-05 13:19) [4]

ОК ШПАСИБО!


 
alienserg   (2004-07-06 05:16) [5]

пример есть в IndyDemos\Chat



Страницы: 1 вся ветка

Текущий архив: 2004.09.12;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.039 c
14-1093468159
Flashman
2004-08-26 01:09
2004.09.12
Несложная работа для программера среднего уровня


1-1093707686
Seldon
2004-08-28 19:41
2004.09.12
Значение свойства из DFM


14-1093435326
Prohodil Mimo
2004-08-25 16:02
2004.09.12
Какие любимые игрушки у детей программеров?


1-1093546210
JohnJ
2004-08-26 22:50
2004.09.12
упорядочивание


4-1091070356
antonn
2004-07-29 07:05
2004.09.12
CPU Ussage