哈哈,有点明白了,看了ics的wsocket.pas中的一些说明:
If you have to use multithreading, you have two possibilities:
1) Create your TWSocket from your thread's Execute method
2) Attach a TWSocket to a given thread using ThreadAttach.
In both cases, you must set MultiThreaded property to TRUE.
If youdo
n't use one of those methods, you'll end up with a false
multithreaded program: all events will be processed by the main tread !
For both methods to work, you MUST have a message loop withing your thread.
Delphi create a message loop automatically for the main thread (it's in
the Forms unit), butdo
es NOT create one in a thread ! For your convenience,
TWSocket has his own MessageLoop procedure. You can use it from your thread.
Sample program MtSrv uses first method while ThrdSrv uses second method.
Sample program TcpSrv is much the same as ThrdSrv butdo
esn't use any
thread. You'll see that it is able to server a lot of simultaneous clients
as well and it is much simpler.
其实我的思路没有大的问题,问题是ics的wsocket中已经有了消息循环,就是MessageLoop
而我还用application.processmessage来进行异步,看来是多余的,而且有时可能会有些异常,
不知道是不是这个问题?不过我使用ics的http用同样的结构写的一些代码,运行一直很稳定。
看来要对程序做些修改。