Specifying ports when creating sockets?

A

Alex Maccaw

In TCP, when you create a socket to a particular address, the OS chooses
a free port number.

I'd like to either specify that port number, or find out that port
number.

I can easily find the port number like so:
socket.addr[1]

However, that fails when the IO stream is closed. I need to find out the
port number even if the connection is never made. I'm not sure this is
possible, which is why I think the first approach, specifying the port
number, is the way to go.

If you're wondering why I'm doing this, it's to do with STUNT.

Can anybody provide any pointers?
 
A

Alex Maccaw

Alex said:
In TCP, when you create a socket to a particular address, the OS chooses
a free port number.

I'd like to either specify that port number, or find out that port
number.

I can easily find the port number like so:
socket.addr[1]

However, that fails when the IO stream is closed. I need to find out the
port number even if the connection is never made. I'm not sure this is
possible, which is why I think the first approach, specifying the port
number, is the way to go.

If you're wondering why I'm doing this, it's to do with STUNT.

Can anybody provide any pointers?

Ok, somebody has kindly let me know that TCPSocket takes 4 options,
including a local port - oops!

That should solve the issue.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top