再请教WINSOCKSTREAM的创建问题:(200分)

  • 主题发起人 主题发起人 http1
  • 开始时间 开始时间
H

http1

Unregistered / Unconfirmed
GUEST, unregistred user!
DELPHI的例子
while (not Terminated) and ClientSocket.Connecteddo
begin
try
Stream := TWinSocketStream.Create(ClientSocket, 60000);
try
FillChar(Buffer, 10, 0);
{ initialize the buffer }
{ give the client 60 seconds to start writing }
if Stream.WaitForData(60000) then

begin
if Stream.Read(Buffer, 10) = 0 then
{ if can抰 read in 60 seconds }
ClientSocket.Close;
{ close the connection }
{ now process the request }
...
end
else
ClientSocket.Close;
{ if clientdo
esn抰 start, close }
finally
Stream.Free;
end;
except
HandleException;
end;
end;
奇怪的是,为什么Stream := TWinSocketStream.Create(ClientSocket, 60000)在循环内建立
而不是循环外建立呢?在内建立,变成当接收完,就释放,然后循环再建,这时候如果客户发
数据过来,不就出错了吗????
 
TWinSocketStream的工作模式是在socket的block下面的,当然没有你说的问题了。
至于它在那里建立无所谓吧。
 
不明白,请说清楚些
 
怎么我的 D5 中的 example 却是象你说的,Create 在循环之外?
procedure TMyClientThread.Execute;
var
TheStream: TWinSocketStream;
buffer: string;
begin
{ create a TWinSocketStream for reading and writing }
TheStream := TWinSocketStream.Create(ClientSocket1.Socket, 60000);
try
{ fetch and process commands until the connection or thread is terminated }
while (not Terminated) and (ClientSocket1.Active)do
begin
try
GetNextRequest(buffer);
{ GetNextRequest must be a thread-safe method }
{ write the request to the server }
TheStream.Write(buffer, Length(buffer) + 1);
{ continue the communication (eg read a response from the server) }
...
except
if not(ExceptObject is EAbort) then
Synchronize(HandleThreadException);
{ you must write HandleThreadException }
end;
end;
finally
TheStream.Free;
end;
end;
 
你是CLIENTSOCKET,不是SERVERSOCKET的CLIENTTHREAD例子
 
没人解释了,我给分算了
 
后退
顶部