<div dir="ltr">2013/5/4 Ludo Brands <span dir="ltr"><<a href="mailto:ludo.brands@free.fr" target="_blank">ludo.brands@free.fr</a>></span><br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im">On 05/04/2013 05:05 PM, Zaher Dirkey wrote:<br>
><br>
> On Sat, May 4, 2013 at 5:40 PM, Ludo Brands <<a href="mailto:ludo.brands@free.fr">ludo.brands@free.fr</a><br>
</div><div class="im">> <mailto:<a href="mailto:ludo.brands@free.fr">ludo.brands@free.fr</a>>> wrote:<br>
><br>
> Can you show the code you use? You tested on Windows, linux, Mac, ...?<br>
><br>
><br>
> Only on Windows XP<br>
><br>
<br>
<br>
</div>This is a small test program that works for me on XP and linux:<br>
<br>
program testselect;<br>
<br>
{$mode objfpc}{$H+}<br>
<br>
uses<br>
Classes,sockets,<br>
{$ifdef unix}<br>
unix,baseunix,unixtype<br>
{$else}<br>
ctypes,WinSock2<br>
{$endif}<br>
;<br>
<br>
CONST<br>
LISTENPORT=1234;<br>
var<br>
sock: cint;<br>
sa,clsa:sockaddr;<br>
tv:TTimeVal;<br>
readfds,writefds,exceptfds:tfdset;<br>
c: Integer;<br>
res: cint;<br>
len: tsocklen;<br>
one: Integer;<br>
begin<br>
sock:=fpsocket(AF_INET, SOCK_STREAM, 0);<br>
if sock=-1 then<br>
begin<br>
writeln('socket failed with ',socketerror);<br>
exit;<br>
end;<br>
one:=1;<br>
if fpsetsockopt(sock, SOL_SOCKET, SO_REUSEADDR, @one, sizeof(one))=-1 then<br>
begin<br>
writeln('setsockopt failed with ',socketerror);<br>
exit;<br>
end;<br>
fillchar(sa,sizeof(sa),0);<br>
sa.sin_port:=htons(LISTENPORT);<br>
sa.sin_family:=AF_INET;<br>
sa.sin_addr.s_addr:= INADDR_ANY;<br>
if fpbind(sock,@sa,sizeof(sa))=-1 then<br>
begin<br>
writeln('bind failed with ',socketerror);<br>
exit;<br>
end;<br>
if fplisten(sock,10)=-1 then<br>
begin<br>
writeln('listen failed with ',socketerror);<br>
exit;<br>
end;<br>
c:=1;<br>
repeat<br>
tv.tv_sec:=1;<br>
tv.tv_usec:=0;<br>
{$ifdef unix}<br>
fpFD_ZERO(readfds);<br>
fpFD_ZERO(writefds);<br>
fpFD_ZERO(exceptfds);<br>
fpFD_SET(sock,readfds);<br>
res:=fpselect(sock+1,@readfds,@writefds,@exceptfds,@tv);<br>
if (res=-1) and (socketerror<>ESYSEINTR) then<br>
begin<br>
writeln('select failed with ',socketerror);<br>
exit;<br>
end;<br>
if (res>0) and (fpFD_ISSET(sock,readfds)<>0) then<br>
begin<br>
{$else}<br>
FD_ZERO(readfds);<br>
FD_ZERO(writefds);<br>
FD_ZERO(exceptfds);<br>
FD_SET(sock,readfds);<br>
res:=select(sock+1,@readfds,@writefds,@exceptfds,@tv);<br>
if (res=-1) and (socketerror<>WSAEINTR) then<br>
begin<br>
writeln('select failed with ',socketerror);<br>
exit;<br>
end;<br>
if (res>0) and (FD_ISSET(sock,readfds)) then<br>
begin<br>
{$endif}<br>
fillchar(clsa,sizeof(clsa),0);<br>
len:=sizeof(clsa);<br>
if fpaccept(sock,@clsa,@len)=-1 then<br>
begin<br>
writeln('accept failed with ',socketerror);<br>
exit;<br>
end;<br>
writeln('connection accepted');<br>
c:=c+1;<br>
end;<br>
until c=2;<br>
closesocket(sock);<br>
<br>
end.<br>
<br>
If you run the program and do from a console a<br>
telnet localhost 1234<br>
to connect to the program, it will print 'connection accepted' and close<br>
immediately.<br>
<div class=""><div class="h5"><br>
Ludo</div></div></blockquote></div><div><br></div><div>I think you should make a server and client component and send it to the Free Pascal team. :)</div><div><br></div>-- <br>Silvio Clécio<br>My public projects - <a href="http://github.com/silvioprog" target="_blank">github.com/silvioprog</a>
</div></div>