Klaus Hartnegg wrote:
Hello,
Does fpSelect not work with UDP sockets?
It always returns 0, which means it did not see a packet.
Is anything wrong with this code?
I don't have time to play with that right now, but test it with a port >
1024 before trying a lower-numbered one. What OS are you running on- the
select() semantics vary slightly on Linux compared with e.g. Solaris,
and I don't know where e.g. BSD stands on this.
Uses
UnixType, BaseUnix, Sockets;
procedure abort (reason:string);
begin
writeln (reason);
halt;
end;
var
sock: cint;
adr : {TInet}SockAddr;
rc : cint;
FDS : Tfdset;
begin
sock := fpSocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if sock = -1 then
abort ('Error from fpSocket');
adr.sin_family := AF_INET;
adr.sin_addr.s_addr := INADDR_ANY;
adr.sin_port := htons(53);
rc := fpBind (sock, @adr, sizeof(adr));
if rc <> 0 then
abort ('Error from fpBind');
Writeln ('send udp packet in less than 5 seconds');
Fpfd_zero(FDS);
FpFd_set (sock,FDS);
rc := fpSelect (1,@FDS,nil,nil,5000);
if rc = -1 then
abort ('Error from fpSelect');
if rc > 0 then
Writeln ('Thank you !')
else
Writeln ('Too late !');
end.
--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk
[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal