Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 Can the same port number be use for both, Receiving and transmitting together?

views
     
TSnarf03
post Apr 25 2023, 06:41 PM, updated 3y ago

Look at all my stars!!
*******
Senior Member
4,547 posts

Joined: Dec 2004
From: Metro Prima, Kuala Lumpur, Malaysia, Earth, Sol


This is what i know, maybe wrong, please correct me if im.

When do tcp connection, pc will use a random port number, connect to fixed remote port number and transmit data.

ie when you connect to google.com at port 80, you dont specify what port to use, its the OS decide what port to use, ie a random number 32323, connect to google port 80, when google response, then data return back to port 32323.

Now my question is, if all ports from 1->65535 is used, either on listening, ie http listen at port 80, or transmit and receiving, ie use 32323 to connect to google, waiting for response, but the response take time, so the port remains open. If all of them are in used, can the pc reuse the same occupied port number to make new connection(s) ?

* please dont argue on port 80 http or 443 https kind of irrelevant thing.
iammyself
post Apr 25 2023, 07:24 PM

Getting Started
**
Junior Member
238 posts

Joined: May 2011
So I'm not an expert in networking but from what I understand you can't use a port that is currently in-use to communicate with a different server, in general.

If all 65k ports are in use and you need more outgoing ports, you'll need to get another IP address.

But maybe you can work around that if you try hard enough.

Additional reading for you, I'm too tired to read now:-

https://stackoverflow.com/questions/1438870...euseport-differ
TSnarf03
post Apr 25 2023, 07:28 PM

Look at all my stars!!
*******
Senior Member
4,547 posts

Joined: Dec 2004
From: Metro Prima, Kuala Lumpur, Malaysia, Earth, Sol


QUOTE(iammyself @ Apr 25 2023, 07:24 PM)
So I'm not an expert in networking but from what I understand you can't use a port that is currently in-use to communicate with a different server, in general.

If all 65k ports are in use and you need more outgoing ports, you'll need to get another IP address.

But maybe you can work around that if you try hard enough.

Additional reading for you, I'm too tired to read now:-

https://stackoverflow.com/questions/1438870...euseport-differ
*
oh the same port can be use once for each different ip address ?
Satori 14118a
post Apr 25 2023, 07:34 PM

Regular
******
Senior Member
1,006 posts

Joined: Sep 2014


QUOTE(narf03 @ Apr 25 2023, 07:28 PM)
oh the same port can be use once for each different ip address ?
*
Short answer, yes.
iammyself
post Apr 25 2023, 08:09 PM

Getting Started
**
Junior Member
238 posts

Joined: May 2011
QUOTE(narf03 @ Apr 25 2023, 07:28 PM)
oh the same port can be use once for each different ip address ?
*
Just to be clear we're talking about the source/client IP address here, e.g. the router's public IP address.

Technically they aren't the same port anymore because they'll have different IPs. E.g.

123.333.111.0:34567
123.333.111.1:34567

This post has been edited by iammyself: Apr 25 2023, 08:17 PM
TSnarf03
post Apr 25 2023, 08:24 PM

Look at all my stars!!
*******
Senior Member
4,547 posts

Joined: Dec 2004
From: Metro Prima, Kuala Lumpur, Malaysia, Earth, Sol


QUOTE(iammyself @ Apr 25 2023, 08:09 PM)
Just to be clear we're talking about the source/client IP address here, e.g. the router's public IP address.

Technically they aren't the same port anymore because they'll have different IPs. E.g.

123.333.111.0:34567
123.333.111.1:34567
*
not talking about router in particular, its an intranet application.

i think if you do that kind of spam through internet, your isp might just block and ban you.

i dont think the ip can simply just change, cause without correct ip, the return package wont be able to come back to you.
iammyself
post Apr 25 2023, 08:42 PM

Getting Started
**
Junior Member
238 posts

Joined: May 2011
QUOTE(narf03 @ Apr 25 2023, 08:24 PM)
not talking about router in particular, its an intranet application.

i think if you do that kind of spam through internet, your isp might just block and ban you.

i dont think the ip can simply just change, cause without correct ip, the return package wont be able to come back to you.
*
So I don't know what is the context you're working with.

But I was just sharing some common networking rules.

The IPs and ports are not changing for active connections. They're added for new connections.
TSnarf03
post Apr 25 2023, 08:46 PM

Look at all my stars!!
*******
Senior Member
4,547 posts

Joined: Dec 2004
From: Metro Prima, Kuala Lumpur, Malaysia, Earth, Sol


QUOTE(iammyself @ Apr 25 2023, 08:42 PM)
So I don't know what is the context you're working with.

But I was just sharing some common networking rules.

The IPs and ports are not changing for active connections. They're added for new connections.
*
I don't think IP can change unless u manually do it, the pc won't know if the 'new' IP available or not, it's possible utilised by other equipment. Like 192.168.0.1 to 192.168.0.254 all used up.
flashang
post Apr 25 2023, 11:49 PM

Casual
***
Junior Member
355 posts

Joined: Aug 2021


If you think from the other direction :

A network service is waiting for "any" incoming connection,
and it can handle a lot of request from different clients and reply.

It is using 1 port for both receive and transmit.

(e.g. web server using port 80 receive from many clients and reply to them)

smile.gif


TSnarf03
post Apr 25 2023, 11:54 PM

Look at all my stars!!
*******
Senior Member
4,547 posts

Joined: Dec 2004
From: Metro Prima, Kuala Lumpur, Malaysia, Earth, Sol


QUOTE(flashang @ Apr 25 2023, 11:49 PM)
If you think from the other direction :

A network service is waiting for "any" incoming connection,
and it can handle a lot of request from different clients and reply.

It is using 1 port for both receive and transmit.

(e.g. web server using port 80 receive from many clients and reply to them)

smile.gif
*
actually its not.

what actually happen SHOULD BE (90% confident), it listen on port 80, but it doesnt just resides on port 80.

like source PC use port 32323 connect to Server port 80, if server accept the connection, it will be move to other free port, it roll for a random number, like 9999, then the new established connection should be

Source PC use port 32323 connect to Server port 9999

then Server re-open port 80, listen again.

correct me if im wrong.

This post has been edited by narf03: Apr 25 2023, 11:54 PM
TSnarf03
post Apr 26 2023, 01:21 AM

Look at all my stars!!
*******
Senior Member
4,547 posts

Joined: Dec 2004
From: Metro Prima, Kuala Lumpur, Malaysia, Earth, Sol


oh it seems im wrong, once dig deeper then only know

[source ip, source port, destination ip, destination port]

must be unique for each connection.

that means if the source pc uses the same ip and port number, the server must change port or ip for multiple connections. but if the client change port or ip, then the server need not to change ip or port.

so if the server port is fixed, any clients can connect to that server port 65535 times, using all different source port, and additional 65535 times for every additional ip.
junyian
post Apr 26 2023, 08:27 AM

Casual
***
Junior Member
401 posts

Joined: Jan 2003


You can read up on sockets programming to find out more.

You're mostly correct already. A connection come in pairs. A source IP+port, and destination IP+port. The connection can be specified as TCP, UDP, etc.
The destination (i.e. server) will "listen" on a IP+port (e.g. 80, 443, etc.) and accept connections. After the server accepts connections, it can react to the incoming packets. A server can accept connections from more than 1 source.

The source (client) will connect to this listening destination using a random high port and can send data as soon as the connection is established.

If you see some apps transfering connections to different ports, that's just the server-client protocol. Nothing to do with how TCP/UDP connections work.

This post has been edited by junyian: Apr 26 2023, 08:28 AM
WongGei
post Apr 27 2023, 05:58 PM

Regular
******
Senior Member
1,206 posts

Joined: Dec 2007
From: Kuala Lumpur
QUOTE(narf03 @ Apr 25 2023, 08:46 PM)
I don't think IP can change unless u manually do it, the pc won't know if the 'new' IP available or not, it's possible utilised by other equipment. Like 192.168.0.1 to 192.168.0.254 all used up.
*
You can add multiple IPs to the same hardware port. One Ethernet port can be assigned with the different IPs.


 

Change to:
| Lo-Fi Version
0.0186sec    0.71    5 queries    GZIP Disabled
Time is now: 24th December 2025 - 05:38 PM