Can a web browser client connect directly to a remote websocket server? - websocket

Assuming I have an apache server with an html page, can I include javascript on that html page that attempts to connect to `ws://remote-server.com:24325' to receive messages from the remote host? Most examples I see online are having html pages with javascript that connect to a localhost websocket server like: ws://localhost:24325

Yes, you can use Javascript in your page to connect to a remote server via a webSocket connection. That's what the webSocket functionality built into a browser is for.
The localhost examples you see are probably just examples for local development testing.
Of course, in order to connect to a given host, that host must be running a webSocket server and be accepting incoming connections.

Related

Remote Websocket server performance

I have created a php websocket server, and a php websocket client, the websocket client communicate with the server using JSON format, each message means an operation to handle by the websocket server.
when running both the client and the server in localhost I can reach about 35 operations/sconds, and the same results when running both client and websocket server on the production server, but running client in locahost (my machine) with production websocket server (remote) that only results in 5 operations/seconds.
What could be the reason behind that bad performance when using remote websocket server?
Solved by changing websocket client app logic (sending messages asynchronously instead of synchronously), by using that approach we have increased the score to more than 100 operations/s.
Credits to Jérôme Richard (See the question comments)

Can Chrome and Safari access two different ports from the same page?

Currently my browser based application connects via port 7000 for both https web pages and websockets communication.
I understand that for security reasons, the browser will not let you connect to different IP addresses at the same time within the page.
My question is can my web page access the server (https port 443) for web page acquisition and then within the page open a https/wss.websocket connection to a different port (assuming the server is setup to accept a connection on that different port)?
Thanks.
The answer is YES.
I was hoping to get an answer so I would not have to design a test - but I did - and I can connect with WS on a different port than the port used to acquire web pages.

How to get a web server to send outbound http requests through local fiddler proxy?

I'm running a local web server written in Go and I can debug traffic going to it from my browser; but, I can't see the http request that it makes to external services.
Do I have to run some particular configuration of the web server in order to get the traffic to appear in fiddler? It is running as a background process.
Short answer: you can't...
...unless your web application is written to open a connection to a Proxy server and route requests through that connection (e.g. connect to a remote proxy, and then send requests through it).
Typically what developers do is just dump the Web Request/Response to a debug file to inspect during development (or to debug on a live server, by enabling it with a flag at runtime).
Fiddler is a "proxy" service/server. When you are using it normally to debug browser requests, your Browser is configured to connect to a Proxy server. That is, it will send all web requests through your fiddler's local server (I think it's localhost:8888 if i remember from my Windows days of using Fiddler) which in turn makes a connection to your local web server that you are debugging.
You can read more about Proxies at Wikipedia.
In that picture above, your local web server would be Alice. Meaning, Alice would need to be configured to connect to a proxy server and then make web requests through it.
EDIT:
(for the "I really need this" crowd)
If you really want to modify your web server to send requests through a proxy, there are a few Go packages already written to help you. GoProxy is one such package.

Internet access via browser

Is it possible to use browser's internet connection for other application?
I'm in environment where browser is the only application that may access internet connection. Meanwhile, I need to run maven projects which needs internet access to download the required JARs.
I was thinking about creating Proxy Server in Chrome extensions or other browser. But, I hope I can find another easier way.
Sounds like Selenium WebDriver is what you need. You could try to redirect the download to browser or try to programmatically simulate browser.
Yes it is possible.
Recently I created a http_proxy server in Java which start 3 socket servers:
Http server to receive user request, and
WebSocket server to allow Chromium extension to create connection to the http_proxy server.
Http Server to receive response body from Chromium.
So, there will be 3 socket connections:
To receive http user request and send back the content, and
To send the URL requested to Chromium browser
When response received by browser (via Xhr), it will do HTTP POST to http_proxy server to send the content.
That's all!

handle CONNECT requests in a websocket server

My websocket server listens on port 8080 with no proxy.
Most of the time I'm getting requests with the Upgrade Websocket header and it works fine.
Sometimes I'm getting HTTP CONNECT requests.
Is this a valid request?
Does it means that there is a proxy server between the client and the server?
How my server is suppose to respond to the CONNECT request?
Thanks
You are getting CONNECT requests because you are likely to have configured your browser to use a proxy. If you directed your browser to use port 8080 on your local IP address, it will assume there is a proxy and that means when you ask for a secure connection, the browser leads with CONNECT.
You will need to add support for SSL/TLS tunnelling to your server to deal with this.

Resources