我也被你搞糊涂了,但是下面的程序我调试通过了,你原封不动粘上试试!!!
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Menus, StdCtrls, Buttons, ScktComp, ExtCtrls, ComCtrls;
type
TChatForm = class(TForm)
ClientSocket: TClientSocket;
Edit1: TEdit;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Disconnect1Click(Sender: TObject);
procedure ClientSocketRead(Sender: TObject; Socket: TCustomWinSocket);
procedure Timer1Timer(Sender: TObject);
protected
IsServer: Boolean;
end;
var
ChatForm: TChatForm;
Server: String;
count:integer;
implementation
{$R *.DFM}
procedure TChatForm.FormCreate(Sender: TObject);
begin
clientsocket.Active := True;
count:=0;
end;
procedure TChatForm.Disconnect1Click(Sender: TObject);
begin
ClientSocket.Close;
end;
procedure TChatForm.ClientSocketRead(Sender: TObject;
Socket: TCustomWinSocket);
begin
inc(count);
edit1.text:=format('%d %s ',[count,Socket.ReceiveText]);
end;
procedure TChatForm.Timer1Timer(Sender: TObject);
begin
clientSocket.Socket.SendText('aaa');
end;
end.