?
Solved

how check socket's close

Posted on 2001-07-01
7
Medium Priority
?
342 Views
Last Modified: 2008-03-17
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
Comment
Question by:tsjit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6243893
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
 

Author Comment

by:tsjit
ID: 6243989
 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
 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6244034
I use MSVC 6.0. You could check is this error for SOCKET_INVALIDHANDLE that mean that your socket is closed.
0
Technology Partners: 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!

 
LVL 10

Expert Comment

by:makerp
ID: 6244087
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
 

Author Comment

by:tsjit
ID: 6244219
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
 
LVL 11

Expert Comment

by:griessh
ID: 6820141
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
 

Accepted Solution

by:
ComTech earned 0 total points
ID: 6837812
This question will be moved to PAQ.

Regards,
ComTech
CS @ EE
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question