Home > Back-end >  UdpSocket how to get the machine IP and port
UdpSocket how to get the machine IP and port

Time:10-06

I use UdpSocket specifies the remote machine's IP and port, and then send the data, I think UdpSocket local IP and will take the local port get together to send to each other, how to do, thank you,

My_UdpSocket1. LocalPort
My_UdpSocket1. LocalHostAddr

Can't get a null value,

CodePudding user response:

Up a little, waiting for the master,

CodePudding user response:

Delphi section in cold and cheerless

CodePudding user response:

Delphi is terrible,

CodePudding user response:

Master really rarely now, ha ha

CodePudding user response:

The function Sckt_GetLocalIP: string;
Type
TarrPInAddr=array [0.. 10] of PInAddr;
ParrPInAddr=^ TarrPInAddr;
Var
PHost: PHostEnt;
P: ParrPInAddr;
Buf: an array of Char [0.. 63];
I: Integer;
The begin
Result:=';
If gethostname (buf, SizeOf (buf))=0 then
The begin
PHost:=gethostbyname (buf);
If pHost=nil then
The Exit;
P:=ParrPInAddr (pHost ^. H_addr_list);
I:=0;
While p ^ [I] <> Nil do//to take the last one is the local IP
The begin
Result:=inet_ntoa (p ^ ^ [I]);
Inc (I);
end;
end;
end;


WSAStartup (WINSOCK_VERSION, WSAData);
WSACleanup

CodePudding user response:

LocalPort?
RemotePort or PeerPort
  • Related