Thread: how to know port is free

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    1

    Angry how to know port is free

    Hi;

    Fyi, i've created few connection let say with port 5001, 5002 .... now i've stop & kill the connection for port 5002, and before i restart a new connection with using same port 5002, how do i make sure:

    - the port is free , no more listen / close_wait

    then the program will only to invoke create_conn() procedure?

    tq.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    The only way I can think of to check whether a particular port is free is to attempt a bind() on that port. If the bind() fails with WSAEADDRINUSE (or the Linux equivalent), then you know that the port is already in use.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. serial port to poll on request
    By infineonintern in forum C++ Programming
    Replies: 2
    Last Post: 06-11-2009, 06:52 AM
  2. Parallel Port IO ops not working properly
    By microtechno in forum Linux Programming
    Replies: 16
    Last Post: 06-08-2009, 12:33 PM
  3. Concurrent chat, Sockets
    By jakemott in forum Linux Programming
    Replies: 6
    Last Post: 11-29-2008, 05:41 PM
  4. multiplexing
    By kaijuu in forum C Programming
    Replies: 0
    Last Post: 03-29-2008, 06:47 AM
  5. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM