有用线程编写的socket程序吗???有的话借给小弟参考一下(急用!!!)
E-mail:[email protected]
E-mail:[email protected]
解决方案 »
- delphi里wwDBComboBox的使用
- 用定时器计算时间之差准吗?
- delphi7游戏呼出外挂窗口
- 如何才能把一条dbgrid内得记录传到另一个form内呢?请高手指导!在线等啊!
- 怎样在dbgrid中显示表的所以记录??
- 急,急,请高手指教!答者再给高分!
- 如何快速地在adoquery中查找?
- delphi生成的exe文件如何防止别人修改里面的超级链接
- 请问timestamp是个什么东东。是用来做什么用的。thanks
- 我用10个edit来实现输入,怎样实现按下enter键之后,输入焦点的转移/?也就是如何从一个edit到另外一个edt??
- 计算字段是否可以进行总计?
- 文件夹更名,为什么通不过?
Threads for server connections are descendants of TServerSocketThread. Because of this, you can抰 use the New Thread object dialog. Instead, declare your thread manually as follows: TMyServerThread = class(TServerClientThread);To implement this thread, you override the ClientExecute method instead of the Execute method.
Implementing the ClientExecute method is much the same as writing the Execute method of the thread for a client connection. However, instead of using a client socket component that you place in your application from the Component palette, the server client thread must use the TTcpClient object that is created when the listening server socket accepts a client connection. This is available as the public ClientSocket property. In addition, you can use the protected HandleException method rather than writing your own thread-safe exception handling. For example:procedure TMyServerThread.ClientExecute;var
Stream : TWinSocketStream;
Buffer : array[0 .. 9] of Char;
begin
{ make sure connection is active }
while (not Terminated) and ClientSocket.Connected do
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't read in 60 seconds }
ClientSocket.Close; { close the connection }
{ now process the request }
...
end
else
ClientSocket.Close; { if client doesn't start, close }
finally
Stream.Free;
end;
except
HandleException;
end; end;
end;Warning: Server sockets cache the threads they use. Be sure the ClientExecute method performs any necessary initialization so that there are no adverse results from changes made when the thread last executed.To use your thread, create it in an OnGetThread event handler. When creating the thread, set the CreateSuspended parameter to False.