Z
zhousi
Unregistered / Unconfirmed
GUEST, unregistred user!
由于种种原因,老板要求用sock实现http协议get的发送(保持连接的,普通的ie就是
非连接的,通俗点就是clientsocket要保持active=true),所以我就改写了杜长胜的
dcs-httpserver(网上有开放代码),自己写了客户端,但后来发现,每发送一次数据后
客户断就被断开了。下面是杜长胜的一段程序,大家帮帮我,看怎么改
procedure TServerThread.ClientExecute;
var
Stream : TWinSocketStream;
Buffer Char;
buffer1: array[0 .. 1023] of Char;
size,i,alllen: integer;
MyFStream:Tfilestream;
head:string;
tttype:accepttypekind;
temp:string;
cf1char;
rechar;
sbuf:string;
relong:integer;
begin
head:=format('%s',['HTTP/1.0 200 OK'])+#13+#10;
head:=head+'Server: dcs-http-server/1.0'+#13+#10;
head:=head+'Date: Thu, 06 Dec 2001 15:08:55 GMT'+#13+#10;
try
while (not Terminated) and ClientSocket.Connected do
begin
Stream := TWinSocketStream.Create(ClientSocket, 30000);
FillChar(Buffer1, 1024, 0);
if Stream.WaitForData(20000) then
begin
if Stream.Read(Buffer1, 1024) = 0 then
ClientSocket.Close
else
begin
tttype:=accepttype(buffer1,requestfilename);
case tttype of
requesthead:
begin
ClientSocket.SendText(head+#13+#10);
ClientSocket.Close;
end;
requestget:
sendfile(stream);
end;{end case}
Stream.Free;
exit; //加了exit 也没有用
ClientSocket.Close;
end;
end
else
ClientSocket.Close;
end;
except
//HandleException;
end;
end;
这里他用了线程,不知道他怎么结束线程(我对线程不太熟悉)
非连接的,通俗点就是clientsocket要保持active=true),所以我就改写了杜长胜的
dcs-httpserver(网上有开放代码),自己写了客户端,但后来发现,每发送一次数据后
客户断就被断开了。下面是杜长胜的一段程序,大家帮帮我,看怎么改
procedure TServerThread.ClientExecute;
var
Stream : TWinSocketStream;
Buffer Char;
buffer1: array[0 .. 1023] of Char;
size,i,alllen: integer;
MyFStream:Tfilestream;
head:string;
tttype:accepttypekind;
temp:string;
cf1char;
rechar;
sbuf:string;
relong:integer;
begin
head:=format('%s',['HTTP/1.0 200 OK'])+#13+#10;
head:=head+'Server: dcs-http-server/1.0'+#13+#10;
head:=head+'Date: Thu, 06 Dec 2001 15:08:55 GMT'+#13+#10;
try
while (not Terminated) and ClientSocket.Connected do
begin
Stream := TWinSocketStream.Create(ClientSocket, 30000);
FillChar(Buffer1, 1024, 0);
if Stream.WaitForData(20000) then
begin
if Stream.Read(Buffer1, 1024) = 0 then
ClientSocket.Close
else
begin
tttype:=accepttype(buffer1,requestfilename);
case tttype of
requesthead:
begin
ClientSocket.SendText(head+#13+#10);
ClientSocket.Close;
end;
requestget:
sendfile(stream);
end;{end case}
Stream.Free;
exit; //加了exit 也没有用
ClientSocket.Close;
end;
end
else
ClientSocket.Close;
end;
except
//HandleException;
end;
end;
这里他用了线程,不知道他怎么结束线程(我对线程不太熟悉)