I wouldn't use a library for UDP. UDP is a very simple protocol (as you can only recieve full datagrams every transmission is only a single read or write).
With the sockets unit this is very easy:
uses sockets;
var
Sock: TSocket;
Addr: PSockAddr_in;
AddrLen: PSizeInt;
AString: String;
DataSize: SizeInt;
begin
Sock := fpsocket(AF_INET, SOCK_DGRAM, 0);
if Sock < 0 then
WriteLn('Something went horribly wrong');
New(Addr);
New(AddrLen);
try
// Send a string stored in AString to HOST_IP at PORT:
// Set address of receiver
Addr^.sin_family := AF_INET;
Addr^.sin_port := HToNS(PORT);
Addr^.sin_addr.s_addr := LongWord(StrToNetAddr(HOST_IP));
// perform sending operation
fpSendTo(Sock, Pointer(AString), AString.Length, 0, Addr, SizeOf(Addr^);
// Receive Data and write to AString:
SetLength(AString, 512); // 512 is the maximum datagram size in many implementations
DataSize := fpRecvFrom(Sock, AString, AString.Length, 0, Addr, AddrLen);
SetLength(AString, DataSize);
WriteLn('Data received from ', NetAddrToStr(Addr^.sin_addr.s_addr), ': ' . AString);
finally
Dispose(Addr);
Dispose(AddrLen);
end;
end;
Or to simplify:
uses sockets;
procedure SendString(Sock: TSocket; const AHost: String; APort: Word, const Data: String);
var
Addr: TSockAddr_IN;
begin
Addr^.sin_family := AF_INET;
Addr^.sin_port := HToNS(APort);
Addr^.sin_addr.s_addr := LongWord(StrToNetAddr(AHost));
fpSendTo(Sock, Pointer(Data), Data.Length, 0, @Addr, SizeOf(Addr));
end;
procedure ReceiveString(Sock: TSocket; out SenderHost: String; out SenderPort: Word): String;
var
addr: PSockAddr_IN;
addrLen: PSizeInt;
DataSize: SizeInt;
begin
New(addr);
New(addrLen);
try
SetLength(Result, 512);
DataSize := fpRecvFrom(Sock, Pointer(Result), Result.Length, 0, addr, addrLen);
SetLength(Result, DataSize);
SenderHost := NetAddrToStr(addr^.sin_addr.s_addr);
SenderPort := NToHs(addr.sin_port);
finally
Dispose(addr);
Dispose(addrLen);
end;
end;
var
Sock: TSocket;
data: String;
HostIP: String = '127.0.0.1';
HostPort: Word = 1337;
begin
Sock := fpSocket(AF_INET, SOCK_DGRAM, 0);
if Sock < 0 then
Exit; // error;
// Send console input to host
ReadLn(data);
SendString(Sock, HostIP, Port, data);
// Receive data:
data := ReceiveString(Sock, HostIP, Port);
WriteLn('Received from ', HostIP, ':', Port, ' ', data);
end;
This is pretty much all you need to work with UDP. I don't see any reason to include some third party librar for using something that can be expressed with two functions having each less than 10 lines of code