Why can't different servers bind to the same port? - apache

I am confused about ports.
I find it odd that we need to bind different servers to different ports.
Example:
Apache binded on 8080, Express.js can't bind on 8080
How does server port binding differ from application port listening?
Example:
Different browsers, ie, chrome, firefox, can listening and communicated on port 80?
This issue came up when trying to run "grunt test:unit". There was a tomcat server that was already bound to 8080, but the server grunt starts, middleware I believe, is able to startup, but it is not able to to capture the browser. Stopping the tomcat server made things work.

Actually, Firefox, Chrome, etc. use different source ports. They don't listen on ports; they connect to remote servers. The servers are listening on one port (80). The source port from which the browser connects is chosen randomly and is a high number. You can check this using netstat. Their destination port is the same (80).
The reason why you can't have multiple servers binding to the same port* is because the operating system wouldn't know which application to hand off an incoming connection to.
*actually, you can, but it's complicated. SO_REUSEPORT

The reason only one application can control/listen on a port at one time is this:
When the OS receives a request for, say, port 80, and there were two apps listening on it, how is it supposed to know which app to pass on the request to?
The reason multiple apps can access the web at once is because they don't do it the same way - they use an unused port (maybe something like 62332 or whatever) and only the destination is port 80, for example.
That's what ports are for - so that you can run more than one server at once per machine.

Related

Can't Port Forward To Ubuntu Web Server

I've set up an Ubuntu Web Server to host a game that uses port 25565.
I've set the router to port forward that port to the web server and gave the web server a static local IP. I've done this before using my own PC as the server.
When I try accessing the web server on that port using it's local IP I have no problem at all.
But, when I try accessing it from outside the network, I can't connect.
I've opened my router's list of DHCP clients and the web server is only listed there sometimes without a pattern I've been able to see.
Why I think the error is at my router:
I've installed Wireshark on the server to see if Apache was somehow blocking the web packets upon arrival. I tried opening all ports and I tried opening port 10000 which webmin uses (I'm able to connect to it locally). Neither has been successful.
Although I'm not experienced in the field, I don't think the packets get to Apache.
Please assist. Thank you!
Does your router hold the external IP address, or an internal one?
If it holds a private IP like 192.168.x.x, 10.x.x.x, or 172.16.x.x, then you would need to setup port forwarding on whatever device your router is connected to.
I've managed to fix it by changing the web interface of the port forwarding from atm1.1 to ppp1.1. It was just luck, as I understood it's web protocols but I don't know why it worked.
Thanks everyone for the help!

Unable to connect to different HTTP port on server

I am new to WCF Services, I have developed a WCF service library hosted within a Windows Service. The service end point is http://servername:9980/ApplicationServer/ServiceName.
When I run this service on local system and try to connect using my application, everything works fine.
The problem starts when I deploy this service on server system, none of my application can use this service, even the browser says page not found. Though, if I remove the specific port number from the endpoint all works well.
I have already opened all the ports in Windows Firewall including Client and Server. Also proper exceptions are made to the router firewall, still I am not able to host the service on specific port. I have even tried by switching firewall off on both client and server system.
Thank you in advance.
-Ashish Sharma
When you remove the specific port number it defaults to port 80.
So there is something that is blocking the other port.
Try using the Telnet command to check if the port is open (you may have to enable telnet)
As you have allready checked the firewalls, it could be urlscan or a network device.

Which port should I run WebSockets server on if 80 is already used by Apache?

I created a WebSockets app to provide communication between connected clients, but I'm concerned about corporate firewalls and ISP rules that might block the port 8080 it's using. But the usual HTTP port 80 (that really no one would block) is already used by Apache on that server to provide the functionality for the rest of the app (which is a clasic web app running on PHP).
What are my options there? Are my concerns misplaced?
One option is to set up an Apache reverse proxy to make your app available via port 80. See (for example) Running a Reverse Proxy in Apache.

Dynamic port

Doesn’t the dynamic ports keep changing? If yes, wont these ports change and communication stop? Please advice.
If I understand your question, then in short, no.
When your HTTP client (aka web browser) opens a connection the operating system picks a random port number from the dynamic (or "ephemeral") range.
All of the communications for that connection continue to use that same port.
Only when a new connection is opened is another port chosen.
To clarify the other end...
Servers of "standard application protocols", like HTTP and FTP have a port assigned to them by a standards body IANA. For example, in the case of HTTP, the default port is "80".
Unless the client selects a non-standard port, web connections are always made to port 80.
The web server is always listening on port 80, it never goes anywhere.
Separately, some protocols use "dynamic protocol assignment", where the protocol number of a service can change, but there is a way to make sure the changing port number is known.

I want to host my own home web server. I installed Apache already but I can't log in other computers

I'm using Windows Vista, I have Apache installed already. Apache is working great, but I want to allow my website to be viewed publicly.
When I entered my ip address(the one hosting the website) on other computers, the page doesn't show up. It just loads but don't show up.
How can I edit my httpd to allow everyone to have access to my website?
Thanks
-- EDITED
Yes, I forwarded it already. Here's the screenie:
alt text http://www.picamatic.com/show/2009/02/26/09/29/2470958_522x128.jpg
Is it correct way? Or do i need to change the port?
You will need to configure the server's firewall to allow incoming connections, and your router to forward connections to the servers.
Also be aware that many ISPs block incoming port 80 connections to avoid having their customers host their own sites (Check your ISP's contract, you may be violating it by hosting a web server)
It's possible to set your router to use a different port and forward it as port 80 to your server if your ISP is blocking port 80. Check with your router's user's manual about forwarding ports. Some routers might not support changing the incoming port to a different one, in which case you would have to change the port Apache runs on as well.
From your screen shot set the public port to something other than 80 (by convention use a port between 1024–49151), and leave the private port to 80.
Also, make sure you're using your public IP on other clients. Do not use the 192.168.. addresses, they're meant only for private networks.
Outside users should then be able to use the link http://[your public router IP]:[new port] to connect.
Be sure if you are using any type of router that you enable "IP forwarding" otherwise your server remains hidden behind it.
This option can be changed on the configuration webpage for the router.
`bstpierre' is correct in that some ISP's block port 80. I use port 8080 myself. Good luck!