Thread: closesocket and shutdown

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879

    Red face closesocket and shutdown

    Ok, this has been bothering me for a while. I read on MSDN that you should always call closesocket() after you create a socket using socket(). So I do it. But what I would like to know, is can the socket be re-opened, or does a new socket have to be created? Like, can I do this:
    Code:
    SOCKET s = socket(...);
    connect(s, ...);
    closesocket(s);
    
    connect(s, ...); //Is this ok?
    (...)
    
    //Or do I have to do this
    SOCKET s = socket(...);
    connect(s, ...);
    closesocket(s);
    
    SOCKET s2 = socket(...);
    connect(s2, ...);
    (...)
    If not, would it work if I used shutdown() instead?

    **EDIT**
    Also, am I right that closesocket() will cause the other end to get a recv() of 0 bytes?
    Last edited by Hunter2; 08-01-2003 at 08:01 PM.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. shutdown()
    By Hunter2 in forum Networking/Device Communication
    Replies: 6
    Last Post: 03-18-2004, 07:43 PM