All,

I have socket application which needs to use the same socketid within a
defined range.
The steps are
1) Create socket --> using socket()
2) send, recv..etc..functions
3) Closesocket --> using closesocket()
4) Create socket --> using socket(). The application needs the same
socket id as obtained from the 1st socket call.
Since I have already closed the socket, the wince is expected to return
the same socket id.

But it is not.

Linux and other OS does it that way, where if socket is closed, the
next socket call would return the closed socket id.

Any inputs..hints.. help..anything would be very very helpful

thanks
Arun

Re: Closesocket by Paul

Paul
Mon Apr 25 14:32:21 CDT 2005

Why would it need to do that?! Don't count on the *value* of a socket
handle ever. That's really, really bad programming practice.

Paul T.

<arun_kalmanje@yahoo.com> wrote in message
news:1114364912.124148.299030@g14g2000cwa.googlegroups.com...
> All,
>
> I have socket application which needs to use the same socketid within a
> defined range.
> The steps are
> 1) Create socket --> using socket()
> 2) send, recv..etc..functions
> 3) Closesocket --> using closesocket()
> 4) Create socket --> using socket(). The application needs the same
> socket id as obtained from the 1st socket call.
> Since I have already closed the socket, the wince is expected to return
> the same socket id.
>
> But it is not.
>
> Linux and other OS does it that way, where if socket is closed, the
> next socket call would return the closed socket id.
>
> Any inputs..hints.. help..anything would be very very helpful
>
> thanks
> Arun
>



RE: Closesocket by coreyb

coreyb
Wed May 04 23:14:23 CDT 2005

I agree with Paul.

The socket handle value is opaque and you should never try to read its
value or predict what the function will return on any OS including Linux
and NT.

The only reason you get the same value on the desktop is because no one
opened a socket between your closesocket() and socket() calls. There's no
guarantee of that, and the code could fail at any time on those OS's.