Delphi TServerSocket⼀ClientSocket 发送接收消息问题请教

2024-11-03 05:20:53
推荐回答(2个)
回答1:

Procedure TForm1.BitBtn1Click(Sender: TObject);
var
I: Integer;
Begin
for I := 0 to ServerSocket1.Socket.ActiveConnections -1 Do
Begin
//if ServerSocket1.Socket.Connections[I].SocketHandle = XXX then
ServerSocket1.Socket.Connections[I].SendText('amsg'); //服务端发送
End;
End;

procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
begin
Socket.ReceiveText; //客户端接收
end;

回答2:

一次传送的东西太多了~

定义一个缓冲区<多次传送>
var
Buf: Array[1..2048] of char;