how Detect LAN Cable unplugged when i was reading data from socket

hi friends,
i need your help about my problem :
i hv a function in my application software but i got problem when i was reading data from socket .
it always error if the cable LAN unplugged , the question is :
" How can i detect the LAN cable unplugged before read data from Socket.

this error result :
"Project jps.exe raised exception classESocketError with message 'Read Error64, The spesified network name is nolonger Available'. Process stopped. use run to continue."

here my function:

int __fastcall TMyServerThread::WaitForResponse(DWORD miliseconds)
{
int lengthdata, packetlength, counter=1;

try
{
if (Terminated)
return (TERMINATED);

do
{
memset (data_packet,0,sizeof(data_packet));

if (!ClientSocket->Connected || Terminated)
return (TERMINATED);

if (Stream->WaitForData (miliseconds))
{
if (!ClientSocket->Connected || Terminated)
return (TERMINATED);

[b] lengthdata = Stream->Read (data_packet,600);//always got error in this command[/b]
if (!lengthdata)
{
counter++;
continue;
}
else
{
packetlength = (int) data_packet[0+BinOfLenght] * 256;
packetlength+= (int) data_packet[1+BinOfLenght];
buf_size = packetlength;
memset (buf_record,0,sizeof(buf_record));
memcpy(&buf_record[0],&data_packet[2+BinOfLenght],buf_size);
return (OK);
}
}
else
{
counter++;
continue;
}
}
while ((counter < 4) && (ClientSocket->Connected) && (!Terminated));
if (counter > 3)
return (TIMEOUT);
else if (!(ClientSocket->Connected) || (Terminated))
return (TERMINATED);
else
return (OK);
}
catch (...)
{
SaveFailureEvent ("Error in WaitForResponse Function.");
return (TERMINATED);
}
}



Thanks alot for the helping

B regards
Linna
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories