多线程通讯问题
服务端收到客户端得信息后如何给客户端返回信息啊
不好意思分不多了,代码如下
void __fastcall TSrvThread::ClientExecute()
{
char temp_buf[1024];
int iRet=0;
while(!Terminated && ClientSocket->Connected)
{
TWinSocketStream *SocketStream = new TWinSocketStream(ClientSocket,60000);
memset(temp_buf,0,sizeof(temp_buf));
iRet = SocketStream->Read(temp_buf,1024);
if(iRet == 0)
{
Terminate();
}
else
{
Form1->Memo1->Lines->Add(temp_buf);
}
delete SocketStream;
}
}
[解决办法]
同线程直接返回用:
Write:从缓冲区中将一定字节的数据写入到流中,返回写入的字节数
不同线程可用事件通知 或 消息 再WRITe
[解决办法]
TWinSocketStream *SocketStream = new TWinSocketStream(ClientSocket,60000);memset(temp_buf,0,sizeof(temp_buf));iRet = SocketStream->Read(temp_buf,1024);if(iRet == 0){ Terminate(); }else{ Form1->Memo1->Lines->Add(temp_buf); ClientSocket->SendBuf(temp_buf,1024);//Add} delete SocketStream; }