Z
zfs88
Unregistered / Unconfirmed
GUEST, unregistred user!
用ServerSocket做个最简单的Web服务器,ServerSocket1端口为:8080,代码如下:
procedure TForm1.ServerSocket1Accept(Sender: TObject;
Socket: TCustomWinSocket);
var
mypage:textfile;
tempstr:string;
begin
memo1.Text:=ServerSocket1.Socket.Connections[0].ReceiveText;
assignfile(mypage,'aa.htm');
reset(mypage);
while not eof(mypage) do
begin
readln(mypage,tempstr);
ServerSocket1.Socket.Connections[0].SendText(tempstr);
end;
ServerSocket1.Socket.Connections[0].Close;
closefile(mypage);
end;
打开IE,打入"http://localhost:8080"可以正常显示'aa.htm'
但当我去掉“memo1.Text:=ServerSocket1.Socket.Connections[0].ReceiveText;”
后却再也不能显示'aa.htm'了。
如果再去掉“ServerSocket1.Socket.Connections[0].Close;”一句,则IE的进度条始终不能显示到头,网页也就无法显示。
谁能解释其中原因?
procedure TForm1.ServerSocket1Accept(Sender: TObject;
Socket: TCustomWinSocket);
var
mypage:textfile;
tempstr:string;
begin
memo1.Text:=ServerSocket1.Socket.Connections[0].ReceiveText;
assignfile(mypage,'aa.htm');
reset(mypage);
while not eof(mypage) do
begin
readln(mypage,tempstr);
ServerSocket1.Socket.Connections[0].SendText(tempstr);
end;
ServerSocket1.Socket.Connections[0].Close;
closefile(mypage);
end;
打开IE,打入"http://localhost:8080"可以正常显示'aa.htm'
但当我去掉“memo1.Text:=ServerSocket1.Socket.Connections[0].ReceiveText;”
后却再也不能显示'aa.htm'了。
如果再去掉“ServerSocket1.Socket.Connections[0].Close;”一句,则IE的进度条始终不能显示到头,网页也就无法显示。
谁能解释其中原因?