Solved

how check socket's close

Posted on 2001-07-01
7
338 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
Independent Software Vendors: 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

688 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