procedure TtestsendThread.Execute;
begin
if WaitForSingleObject(hMutex,INFINITE)=WAIT_OBJECT_0 then
begin
try
FSocket.Active:=true;
if Fsocket.Active then
begin
CoInitialize(Nil);
FQuery.SQL.Clear;
FQuery.SQL.Add('select * from cmppwait');
FQuery.Open;
if FQuery.RecordCount>0 then
begin
FSocket.Socket.SendText('好好!');
end;
end;
finally
CoUninitialize;
end;
end;
ReleaseMutex(hMutex);
end;
procedure TtestreadThread.Execute;
begin
if WaitForSingleObject(hMutex,INFINITE)=WAIT_OBJECT_0 then
begin
FSocket.Active:=true;
if Fsocket.Active then
begin
showmessage(Fsocket.Socket.ReceiveText);
end;
end;
ReleaseMutex(hMutex);
end;
这个是我写的东西!我也不知道到底该怎么写!反正是阻塞的这边写的时候那边不会发送东西的!但是我写的东西和我的服务端连不上,帮我看看吧是什么问题!
This example shows the execute method of a thread used to send requests to a server over a socket connection:
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;