客戶端代碼:
procedure TForm2.ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
var
shost:string;
begin
sHost:=clientsocket1.Socket.LocalAddress;
clientsocket1.Socket.Sendtext(sHost);
end;
procedure TForm2.ClientSocket1Error(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
case errorevent of
eeconnect:showmessage('connect link fail');
eelookup:showmessage('find fail');
eeReceive:showmessage('receive fail');
eesend:showmessage('send fail');
end;
errorcode:=0;
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
clientsocket1.Open;
end;
服務端代碼:
procedure TForm1.FormCreate(Sender: TObject);
begin
serversocket1.Open;
end;
procedure TForm1.ServerSocket1ClientError(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
case errorevent of
eeconnect:showmessage('connect link fail');
eelookup:showmessage('find fail');
eeReceive:showmessage('receive fail');
eesend:showmessage('send fail');
end;
errorcode:=0;
end;
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
sip,str,sremoteaddress:string;
i:integer;
begin
i :=serversocket1.Socket.ActiveConnections;
str:= Trim(serversocket1.Socket.ReceiveText);
sremoteaddress := serversocket1.Socket.Connections[i - 1].RemoteAddress;
listbox1.Items.Add(sremoteaddress);
end;
請幫忙看看。萬分感謝。