J
jb9802
Unregistered / Unconfirmed
GUEST, unregistred user!
[h1][/h1]1、结构说明:我的客户端是一个智能设备会主动的呼指定的服务器,服务器程序是一个“阻塞方式”工作的,线程代码如下:
ThreadCount++;
AnsiString istr;
int ISendCmdNo;
while (!Terminated &&(ClientSocket->Connected==true))
{
try
{
TWinSocketStream *pStream=new TWinSocketStream(ClientSocket,6000);
try{
memset(buffer,0,sizeof(buffer)); //初始化Buffer
istr=GetSendStr();
strcpy(buffer,istr.c_str());
int bufferlen=istr.Length();
//pStream->WaitForData(6000);
Len=pStream->Write(buffer,bufferlen);
if(Len!=0)
{
Synchronize(updatescreenSendCmd);
memset(buffer,0,sizeof(buffer));
// if(pStream->WaitForData(6000))
{
Len=pStream->Read(buffer,sizeof(buffer));
if(Len!=0) //60秒内没有读到
{
ISendCmdNo=StrToInt("0x"+istr.SubString(4,2));
PhoneAlarm->BeforeCodeInit(ISendCmdNo,OnData);
Synchronize(updatescreenAnalyzeCode);
}
}
}
}__finally{
delete pStream;
}
Sleep(1000);
}
catch(...)
{
HandleException();
}
}
ThreadCount--;
3、问题当我把设备从网上断掉后ClientSocket->Connected还是true, 一般过一小段时间以后执行 Len=pStream->Write(buffer,bufferlen); 或 Len=pStream->Read(buffer,sizeof(buffer)); 就出错,错误信息如下:
write error 64, 指定的网络名不再可用
问题很久没有解决了,还请大家仔细研究。
代码:
AnsiString istr;
int ISendCmdNo;
while (!Terminated &&(ClientSocket->Connected==true))
{
try
{
TWinSocketStream *pStream=new TWinSocketStream(ClientSocket,6000);
try{
memset(buffer,0,sizeof(buffer)); //初始化Buffer
istr=GetSendStr();
strcpy(buffer,istr.c_str());
int bufferlen=istr.Length();
//pStream->WaitForData(6000);
Len=pStream->Write(buffer,bufferlen);
if(Len!=0)
{
Synchronize(updatescreenSendCmd);
memset(buffer,0,sizeof(buffer));
// if(pStream->WaitForData(6000))
{
Len=pStream->Read(buffer,sizeof(buffer));
if(Len!=0) //60秒内没有读到
{
ISendCmdNo=StrToInt("0x"+istr.SubString(4,2));
PhoneAlarm->BeforeCodeInit(ISendCmdNo,OnData);
Synchronize(updatescreenAnalyzeCode);
}
}
}
}__finally{
delete pStream;
}
Sleep(1000);
}
catch(...)
{
HandleException();
}
}
ThreadCount--;
3、问题当我把设备从网上断掉后ClientSocket->Connected还是true, 一般过一小段时间以后执行 Len=pStream->Write(buffer,bufferlen); 或 Len=pStream->Read(buffer,sizeof(buffer)); 就出错,错误信息如下:
write error 64, 指定的网络名不再可用
问题很久没有解决了,还请大家仔细研究。