Are there two ports 1234 (outgoing) and 1234 (incoming) or only one which can be used only exclusive

  • Thread starter Thread starter Peter Eisenman
  • Start date Start date
P

Peter Eisenman

Assume we look an a certain port say, port number 1234.

Are there TWO different ports 1234 - one for the outgoing direction and one for the incoming?
Or is there only one port which can be used only in one direction at a certain time: either
as incoming or outgoing?

If the ladder would be true then an already established incoming connection on port 1234 would block
any outgoing connection on the same port.

Peter
 
It is not the latter. Incoming and outgoing ports are separate.

When setting up an INCOMING connection, you bind to a specific port to
listen on, waiting for someone to connect / send something to you. Others
then send their connect requests to that port at your IP address.

When initiating an OUTGOING connection, you specify which port to connect to
at the other (remote) end. You cannot specify which port to use as your
outgoing port.

Regards.
 
Ports are ports. They are essentially, "imaginary". What you are asking
depends on the software that is *controlling* the flow of traffic to/from
any specific port. The controlling software (usually a router or a firewall,
or both) can allow/disallow traffic either in, out or both ways, through
this imaginary port.

-Frank
 
Ports can be open either incoming, outgoing or both. Connections may be
established on the same port in both directions, or on independent inbound
and outbound ports. Download ethereal and watch your tcp/udp traffic. It
will gove you a lot of insight.

....kurt
 
A port is a port is a port. If your local port 1 is receiving data, then no
application can send from port 1 on your machine, regardless of the port
they wish to send to.

However, almost all applications which use sockets/ports are able to
maintain multiple connections at the same time (e.g. mail servers ALL
receive on port 25, and can often have 100s of simultaneous connections from
different servers without a problem). Another process however, cannot use
this port.

e.g. If you configured windows RDP to use port 80, and then wanted to use
port 80 with IIS, IIS will be unable to bind to the port, as it is in use by
another application. RDP however, could have as many connections on port 80
as the protocol supports.

Clear as mud?
 
What a question! What normally happens is as follows.

- Connections are uni-directional (send on one, receive on the other).
- If you want to receive on port 1234, you create a listen on port 1234.
- If you want to send to another machine's port 1234 you create a send
socket and _often_ say "I don't care which of my ports I send from", so your
machine pick one at random (say 24536).

OK, now the more complicated bits.

- If you say "pick a send port at random", there are a set of about 1024
ports from 1 upwards which are never selected because these are user for
known purposes such as telnet, FTP, web (http) etc.
- Sometimes a connection is bi-directional so if someone connects to you on
port 1234 from their port 26475 (say), you send back along that same
connection (from your 1234 to their 26475).
- Lots of partners (potentially) can connect to your 1234 port (if you're
listening) and each connection is uniquely identified by 4 pieces of
information:
- your IP address
- your port
- their IP address
- their port.
Remember that if you have multiple cards, or are "multi-homed", you might
have more than one IP address!

Now there are advantages to wanting to not only listen on port 1234, but
also start connections from it. This is possible on many platforms BUT NOT
on Linux (or at least not the last time I looked!). There are various
"sockets options" which need to be set to do this and Linux is missing
support for one of them (SO_REUSEADDRPORT if I remember correctly).

So, the answer to your question is "depends on what you want to do and on
what platform and how you denote a port".

It might be simpler if you ask a specific question such as "I'm using
program XYZ and want to do THIS - can I?".

Finally, the web is awash with good web pages on sockets. All of the
information and terms above can be found by a quick Google.

Paul DS.
 
Peter said:
Assume we look an a certain port say, port number 1234.

Are there TWO different ports 1234 - one for the outgoing direction and one for the incoming?
Or is there only one port which can be used only in one direction at a certain time: either
as incoming or outgoing?

If the ladder would be true then an already established incoming connection on port 1234 would block
any outgoing connection on the same port.

Peter

Just the one.

But your last comment may be misleading. Just because something's using
port 1234 at /my/ end doesn't mean I can't connect to someone else's
port 1234. A tcp connection is defined by two ip addresses and two
ports; a port on a server has to be known as it defines which program
you're connecting to. A port on a client is (usually) picked by the
system from a pool of free numbers; you don't generally have to worry
about it.
 

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

Back
Top