Solved

how check socket's close

Posted on 2001-07-01
7
318 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
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

770 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