[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 353
  • Last Modified:

how check socket's close

i have a c/s program in unix.but i don't check the close of client's.
  at first ,i check the return of recv,if it equal 0,then the client is close.and i do in my way.
  but if the client host is shutdown.the return of recv is -1.so i couldn't check the status of client's quit.
  how do i do ?
0
tsjit
Asked:
tsjit
1 Solution
 
MadYugoslavCommented:
I recv return -1 that mean some error. If You don't want to check error (some socket get last error function) You can said that it mean Your socket is closed and no more available. That mean that problem is ion your side of communication.
0
 
tsjitAuthor Commented:
 i used socket nonblock.and every time i check the error no ,it is 11.after i shutdown the client's host.the error no is not change.
  qnx is the opration of me.
0
 
MadYugoslavCommented:
I use MSVC 6.0. You could check is this error for SOCKET_INVALIDHANDLE that mean that your socket is closed.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
makerpCommented:
this is from my Stream class, it checks for close and error. it is for windoze but you will get the idea

int Stream::recvData(char *buffer,int len,int option)
{
     int so_far = 0;
     int res = 0;
     so_far = recv(sock,buffer,len,0);
     if(so_far == SOCKET_ERROR || so_far == 0)
     {
          last_error = WSAGetLastError();
          return FAILURE;    
     }
     /* should we wait for 'len' to arrive */
     if(option == RECV_UPTO_LEN)
     {
          while(so_far < len)
          {
               res = recv(sock,buffer + so_far,len - so_far,0);
               if(res == SOCKET_ERROR || so_far == 0)
               {
                    last_error = WSAGetLastError();
                    return FAILURE;
               }
               so_far += res;
          }
     }
     return so_far;
}

0
 
tsjitAuthor Commented:
thank you ,but i am in qnx opration.are you give me more detail about unix and so.because they can not supple WSAGetLastError() or some like this.
         
0
 
griesshCommented:
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to refund the points and PAQ at zero points since nobody had a solution for you.

The link to the Community Support area is: http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner

0
 
ComTechCommented:
This question will be moved to PAQ.

Regards,
ComTech
CS @ EE
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now