即然服务端已收到连接信息就应该没问题,记得上这上面有许多这样的例子,你找一个看看.这里也有一个简单例子:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ScktComp;
type
TForm1 = class(TForm)
ClientSocket1: TClientSocket;//客户端组件
ServerSocket1: TServerSocket;//服务端组件
procedure FormCreate(Sender: TObject);
procedure ServerSocket1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function Get_ComputerName: String;
var
iSize: LongWord;
ComputerName: PChar;
begin
iSize := MAX_COMPUTERNAME_LENGTH + 1;
GetMem(ComputerName, iSize);
GetComputerName(ComputerName, iSize);
Result := ComputerName;
FreeMem(ComputerName);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
with ServerSocket1 do
begin
Port := 5643;
Open; //或者Active := True;
end;
with ClientSocket1 do
begin
Port := 5643;
Host := Get_ComputerName;
Open; //或者Active := True;
end;
end;
procedure TForm1.ServerSocket1ClientConnect(Sender: TObject;//收到连接请求后的回应
Socket: TCustomWinSocket);
begin
Socket.SendText('ClientSocket1 你好!')
end;
procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
begin
ShowMessage(Socket.ReceiveText);//收到服务端回应后的提示!
end;
end.