>>>>> "brekehan" == brekehan <(E-Mail Removed)> writes:
brekehan> I am wondering if it is possible to (open/bind/send on
brekehan> etc.) to the same port more than once?
connect/send: yes; bind: no.
brekehan> For example: Can I have both UDP and TCP going through
brekehan> the same port?
Short answer: yes.
Longer answer: Bad question. UDP port numbers and TCP port numbers
are two separate address spaces. They don't interfere each other.
UDP port 1234 has completely nothing to do with TCP port 1234 (other
than looking alike). They're 2 separate entities.
brekehan> Can I bind two UDP sockets to the same local port on the
brekehan> server side and two UDP sockets on the same port on the
brekehan> client side and keep thier individuality?
I cannot understand your question.
Let's put it this way:
A server process wants to _listen_ to a TCP/UDP port. It has to
"bind" to that port. The OS then associates that port with the
process. Much like how your mobile phone number is associated to your
mobile phone. The OS forwards incoming packets addressed to that port
to the server process -- after packet sequencing (TCP), reassembly and
header stripping. Since one port can only be associated with one
process, you cannot have 2 such server processes binding to the same
port. Otherwise, if you're to write the OS, how would you decide
which process to forward the received packet to? Similarly, you
cannot have 2 separate mobile phones that ring when a single number is
called.
Now, for client processes, this is a slightly different story. When
it needs to contact a server, it "sends" or "connects" to a certain
port (determined by the server) on a remote machine. This is like
making an outgoing call to mobile phones. Different people can call
the same number. It is possible for 2 client processes to be sending
to the same server port. (Each client process actually has its own
local port number, usually an arbitrary one assigned by the OS. This
is used when the server sends replies to the client. This is
different from mobile phones, where the caller's number is not
assigned arbitrarily.)
All in all, the port number (together with IP address) is a number for
addressing the recipient. For each address, only recipient can be
associated. (Otherwise, how should the ambiguity be resolved). But
one address can be utilized by many senders at once.
brekehan> Can I send TCP and SSL/TCP on the same port?
Yes. TCP port numbers are a separate address space from UDP.
brekehan> Trying to look ahead at problems for design phase of C++
brekehan> implementation.
You should make it flexible. Have the programs read the port numbers
from a config file, rather than hardcoding the values.
If parsing config files seem complicated, then you should at least
define symbolic constants (either via #define or simply "const int" in
some header files) for the port numbers. Use a different number for
different components. And refrain from *deriving* the port number
used by one component from another.
With these measures, you can defer the decision on the port number to
a later stage of your project. With #define (or const int), you defer
it to pre-build time. With config files, you further defer it to
post-build time.
--
Lee Sau Dan §õ¦u´° ~{@nJX6X~}
E-mail:
(E-Mail Removed)
Home page:
http://www.informatik.uni-freiburg.de/~danlee