我想问个clientsocket 的线程的问题,高分求助。各位gg Help o (100分)

  • 主题发起人 主题发起人 晓茜
  • 开始时间 开始时间

晓茜

Unregistered / Unconfirmed
GUEST, unregistred user!
本地server 有L_serversocket 和clientsocketthread 线程,通过serversocket接收到 数据
,,把数据给clientsocketthread 创建的clientsocket 与中央计算机通信,,
把数据传给中央计算机的C_serversocket处理,,由clientsocketthread
创建的clientsocket 传给L_serversocket ,L_serversocket 传给客户端的clientsocket
完成通信,,如何得到clientsocketthread 创建的clientsocket .readbuf??
 
你本地server线程中创建的clientsocket是阻塞的还是非阻塞的?如果是非阻塞的,可以将
onread事件赋给线程里的一个事件;如果是阻塞的,其实,线程中最好是用阻塞的,delphi帮
助中有自带的例子:
To write a thread for client connections, define a new thread object using the New Thread Object dialog. The Execute method of your new thread object handles the details of reading and writing over the thread connection. It creates a TWinSocketStream object, and uses that to read or write. For example:

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 (e.g. 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;

To use your thread, create it in an OnConnect event handler.
For more information about creating and running threads, see Executing thread objects.
自己看看吧!
其实,如果仅仅是通信用的话,一个clientsocket就足够了.
仅供参考,呵呵!
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
886
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部