G
gohoo
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
s,c1:Tsocket;
aWSAData:TWSAData;
sa:sockaddr_in;
t1,t2:dword;
flagchar;
begin
flag:=pchar('1');
t1:=gettickcount;
try
if WSAstartup(MAKEWORD(2,2),aWSAData)<>0 then exit;
s:=socket(2,1,6);
if s=INVALID_SOCKET then exit;
sa.sin_family:=pf_inet;
sa.sin_port:=htons(80);//要重用80口的
sa.sin_addr.S_addr:=INADDR_any; //inet_addr("127.0.0.1"
if setsockopt(s,SOL_SOCKET,SO_REUSEADDR,flag,sizeof(flag))=-1
then begin
getlasterror;
exit;
end;
if bind(s,@sa,sizeOF(sa))=socket_error then
begin
closesocket(s);
exit;
end;
self.Caption:='开始监视80端口';
listen(s,5);
while (1) do
begin
memo1.Lines.Add('监听中....');
t2:=gettickcount;
if t2-t1>10000 then exit;
end;
finally
WSACleanup;
end;
end;
//以上是在80端口监听的程序,但是在setsockopt那行过不去,
//该怎么办?那位大虾知道啊,帮个忙??
var
i:integer;
s,c1:Tsocket;
aWSAData:TWSAData;
sa:sockaddr_in;
t1,t2:dword;
flagchar;
begin
flag:=pchar('1');
t1:=gettickcount;
try
if WSAstartup(MAKEWORD(2,2),aWSAData)<>0 then exit;
s:=socket(2,1,6);
if s=INVALID_SOCKET then exit;
sa.sin_family:=pf_inet;
sa.sin_port:=htons(80);//要重用80口的
sa.sin_addr.S_addr:=INADDR_any; //inet_addr("127.0.0.1"
if setsockopt(s,SOL_SOCKET,SO_REUSEADDR,flag,sizeof(flag))=-1
then begin
getlasterror;
exit;
end;
if bind(s,@sa,sizeOF(sa))=socket_error then
begin
closesocket(s);
exit;
end;
self.Caption:='开始监视80端口';
listen(s,5);
while (1) do
begin
memo1.Lines.Add('监听中....');
t2:=gettickcount;
if t2-t1>10000 then exit;
end;
finally
WSACleanup;
end;
end;
//以上是在80端口监听的程序,但是在setsockopt那行过不去,
//该怎么办?那位大虾知道啊,帮个忙??