Sign In/My Account | View Cart  

advertisement

AddThis Social Bookmark Button

Article:
  Incorporating Rendezvous into Your Cocoa Applications, Part 2
Subject:   Cocoa Port Allocation
Date:   2003-07-16 09:36:21
From:   anonymous2
I have been trying similar things. The Apple sample code uses lowlevel bsd functions which I think look a little messy when it can be done using cocoa. My problem is querying a NSSocketPort to find it's port.
for example;


sP = [[NSSocketPort alloc]initWithTCPPort:0];


will allocate a NSSocketPort with an available TCP port (unlike your example that will fail if that port is already taken)


but to advertise the port with NSNetService, the tcp port must be known.


anybody, any ideas?

Full Threads Oldest First

Showing messages 1 through 1 of 1.

  • Cocoa Port Allocation
    2003-10-26 02:34:13  rjimlad [View]

    Ugly, but it should work:

    NSData *address=[sP address];
    struct sockaddr_in remote_addr;
    [address getBytes:&remote_addr length:sizeof(struct sockaddr_in)];

    // take a look at address.sin_port. It *should* be the allocated port.