how to know port is free

This is a discussion on how to know port is free within the C Programming forums, part of the General Programming Boards category; Hi; Fyi, i've created few connection let say with port 5001, 5002 .... now i've stop & kill the connection ...

  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,254
    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, 07:52 AM
  2. Parallel Port IO ops not working properly
    By microtechno in forum Linux Programming
    Replies: 16
    Last Post: 06-08-2009, 01: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, 07:47 AM
  5. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 06:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21