Thread: Changing SOCKADDR_IN Real-Time :: Winsock

  1. #1
    Registered User
    Join Date
    Nov 2001

    Changing SOCKADDR_IN Real-Time :: Winsock


    I am working on a simple message program via IP and TCP protocols. Right now, I ininitialize a listening socket on a default (I set at 21). The user can change the port anytime; however, the actual SOCKADDR_IN that was binded with the listening socket is working on the default port.

    Is there a way to modify the port in a SOCKADDR_IN in real-time? Do I have to close the listening sock and bind it with a new SOCKADDR_IN with the new port?


    P.S. From my experience with ftp servers and clients, I believe you have to "reconnect." Thus I believe you have to close whatever socket and start over. I would like to make sure that is true.

  2. #2
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    This is dynamic port changing here.

    Both listen() and connect() totally ignore the SOCKADDR_IN struct once the call has been made. You can see this yourself if you declare the SOCKADDR_IN struct as a local variable within the same function you call listen(). After the function returns and the struct is deleted from memory, no crashes occur and Winsock is fine; it neither requires nor harvests information from that struct after the initial call.
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

  3. #3
    Registered User
    Join Date
    Nov 2001
    Okay. Thanks.

    One last question.

    Let say you create a listening sock at port 21. Okay. Now let say a user logs on and everything works well. Now, let say you go and change the server port. Afterward, you disconnect the server (close it). Uponing disconnecting the server I assume you close the both the listening socket and the accept socket (disconnect the user as well). Is it possible to reuse both the listening sock and accept socket? In other words, once you call closesocket(...) on one or more sockets, is it possible to reuse them, i.e:

    // listeningsock(used) = WSASocket(...);
    // bind(listeningsock...);
    // listen(...);


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers
    By Big_0_72 in forum C Programming
    Replies: 3
    Last Post: 10-28-2008, 07:51 PM
  2. Is this really true or it's just science fiction?
    By Nutshell in forum A Brief History of
    Replies: 145
    Last Post: 04-09-2002, 06:17 PM
  3. Programming Puns
    By kermi3 in forum A Brief History of
    Replies: 44
    Last Post: 03-23-2002, 04:38 PM
  4. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM
  5. Real Time?
    By Sebastiani in forum C Programming
    Replies: 1
    Last Post: 09-23-2001, 03:33 PM