从ServerSocket获取连接ID

时间:2010-03-24 18:05:22

标签: delphi tcp serversocket delphi-2007

我需要从ServerSocket获取连接ID。通过客户端我发送文本,我需要知道哪个客户端发送文本。任何想法??

3 个答案:

答案 0 :(得分:1)

procedure Tf_serveur.ServerSocket1ClientRead(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  Memo1.Lines.Add(Socket.RemoteAddress+'\>'+Socket.ReceiveText);``
  // Socket.RemoteAddress  is the client ip 
  // Socket.RemoteHost     is the client nameposte
  // Socket.receivetext    is the client text sinding
end;

答案 1 :(得分:0)

我在想他是指套接字的句柄

procedure TForm1.srvrsckt1ClientConnect(Sender: TObject;
  Socket: TCustomWinSocket);
  var connectedClientSockHandle : Integer;
begin
  connectedClientSockHandle := socket.Handle;
end;

答案 2 :(得分:0)

我认为您应该做的是将每个新连接(在onaccept函数中)分配给唯一ID(随机字母/数字),然后从client->服务器发送的每个命令都将包含唯一ID那个客户。