So this might be noobish of me, but I’ll just ask anyways. So I’ve read up on WebSockets and how it works, however, I’m still trying to understand the setup of the schematic WebSocket URL. I know that you have to first call ws:// for HTTP or wss:// for HTTPS, then you have your website URL, then the port, then the URL to the script you are trying to run. However, I still don’t understand why the port is in there, is it required? Why can’t you just do something like http://localhost/the/path/to/the/file.php or https://localhost/the/path/to/the/next/file.asp?
I want to fully understand how WebSockets work before I get myself into a deep hole.
I feel like this applies to pretty much everything in programming and computers really… I think it’s the hardest part to convey to people sometimes. I have some friends that are very deep diver learners like I tend to be… but programming has been such a different experience learning than anything else I’ve learned. There are so many dependent areas of understanding on how all these things work and work together - the best way to learn things as much like @Mittineague said:
I see, I get what you guys are saying, but I should of made myself more clear. What I meant to ask was why have the port in the URL schema if you already have the HTTP request in the beginning? Say you want to use http, the port is normally at 80 so you would just do ws:// to connect to the server and the URL. But if you want to use SSL, you’d use wss:// and the server URL. However, why do you need to specify the port if say you’re already running wss:// for SSL and ws:// for regular HTTP request?
The question is why use both ws://localhost.com:80/the/path/to/the/file.html when ws:// already sends port 80? Or wss://localhost.com:443/the/path/to/the/file.html when wss:// already sends port 443.
Why is it that you have to repeat the same port twice? Or am I misunderstanding how the URL schema works?
If the websocket server is running on port 80 have you tried connecting to ws://localhost.com/the/path/to/the/file.html without the port? You may be answering your own question if it just works.
The reason ports are used is that often a single machine runs multiple servers. e.g.
In this example a standard http server runs on port 8080 and the websocket server runs on 8081.
Try downloading this example and changing the port to 80 and connecting without the port in client.js.