Socket Programming ..help

This is a discussion on Socket Programming ..help within the Networking/Device Communication forums, part of the General Programming Boards category; Is there a library routine in BSD Sockets to get the port no from the of the socket if we ...

  1. #1
    char main() RoshanX's Avatar
    Join Date
    Mar 2003
    Posts
    68

    Socket Programming ..help

    Is there a library routine in BSD Sockets to get the port no from the of the socket if we let BIND() assign a port number for us. ?
    Thanks in advance.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826

    Re: Socket Programming ..help

    Originally posted by RoshanX
    Is there a library routine in BSD Sockets to get the port no from the of the socket if we let BIND() assign a port number for us. ?
    Thanks in advance.
    Why aren't you specifying your own port number? I don't see the point. If you need the socket number, specify it. This should keep you busy for a while.

    I still don't see why you aren't naiming your own port number though.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    char main() RoshanX's Avatar
    Join Date
    Mar 2003
    Posts
    68
    If I use an arbitrary port number, that port might be in use so it can't be binded to that port. What I want to do is , bind to a port ( arbitrary) then announce the port. ( This is just a test applicatoin. Not a big one.).

  4. #4
    Registered User BillBoeBaggins's Avatar
    Join Date
    Oct 2003
    Posts
    107
    I don't remember the exact range of ports, but start at lets say 3000 and then create your socket... attempt to bind to it.. if it fails the bind.. then increment the port and try again.. I haven't seen any callback functions in API for detecting used ports... this might run faster anyways.

  5. #5
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Wouldn't the port number be in the sockaddr struct? I'm just guessing, if one wasn't supplied, wouldn't it assign one to the struct and then attempt the bind? Check that and tell us what happens, I'm interested to know what happens.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. socket programming question, closing sockets...
    By ursula in forum Networking/Device Communication
    Replies: 2
    Last Post: 05-31-2009, 05:17 PM
  2. Socket Help - Multiple Clients
    By project95talon in forum C Programming
    Replies: 5
    Last Post: 11-17-2005, 01:51 AM
  3. when to close a socket
    By Wisefool in forum Networking/Device Communication
    Replies: 5
    Last Post: 11-02-2003, 09:33 AM
  4. problem closing socket
    By Wisefool in forum Networking/Device Communication
    Replies: 2
    Last Post: 10-29-2003, 11:19 AM
  5. socket newbie, losing a few chars from server to client
    By registering in forum Linux Programming
    Replies: 2
    Last Post: 06-07-2003, 11:48 AM

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