WebSocket cannot establish a connection with any address besides 127.0.0.1 or localhost

I built a test app that consists of both an HTML5/WebSocket client and an HTTP/WS server. The servers are written in C#, with my own simple HTTP server and a WS server based on concepts from . The HTTP server listens on 0.0.0.0:5959, and the WS server is listening on 0.0.0.0:5960 (accepting connections from any client but on different ports).

In my index.html file, there's some JavaScript code that establishes a WebSocket connection to

'ws://'+document.location.hostname+':5960/'
(connecting to the same IP address as the webpage but on port 5960). The WS server sends sample data every 100ms, making it a straightforward demo. I'm using Chrome 12.0 on Windows7.

The HTTP server works fine from any client, whether it's a browser on my machine accessing 127.0.0.1:5959 or localhost:5959, or even when a remote machine pings my server's internal IP at 10.122.0.159:5959. Everything functions as expected in the realm of HTTP.

However, the WebSocket only seems to function on 127.0.0.1 and localhost; remote machines can retrieve HTML from 10.122.0.159:5959, yet the WebSocket fails to connect to 10.122.0.159:5960. Even pointing my local browser to its own 10-net address (10.122.0.159:5959) produces the same outcome - the HTML loads but the WebSocket connection does not occur.

Do you have any insights into why this might be occurring? Does CORS mandate that the WS must use the same port as the originating HTTP request? And is there a special exemption for 127.0.0.1?

Thank you,
-Dave

Update
It appears that a proxy server is causing the issue with the ws:// requests. Our company employs a proxy server for content filtering and other functions, which our browsers are configured to use.
Chrome follows IE's proxy settings, and by default, IE does not utilize a proxy server for localhost. When I enable the proxy server for local connections, my ws:// requests to localhost are blocked. Conversely, disabling the "use proxy server" setting allows my server to receive the WS request. The same applies for remote machines - turning off the proxy enables my server to receive the ws:// request.
Therefore, it seems to be related to the proxy configuration rather than CORS or socket issues. Now, I will delve into the proxy settings with our IT team.

Answer №1

WebSocket cross-origin limitations are primarily dictated by CORS security protocols during handshake.

If you're experiencing issues with your WebSocket server only accepting connections on localhost, consider adding debug output to the OnClientConnect routine in Nugget's WebSocketServer.cs file to monitor socket connection events. If you suspect the issue lies elsewhere, utilize Wireshark to compare local and remote connections.

Additionally, when using the SilverLight WebSocket prototype in IE 9, note that ports 4502-4534 are designated for WebSocket connections. The restriction may be lifted for localhost connections.

Answer №2

It definitely ended up being a proxy issue.
Instead of trying to convince our IT department to fix it (good luck with that, right?) I decided to disable the proxy for 10.122.0.159 ([Instructions for IE/Chrome][1]). I attempted to also disable it for the ws:// protocol but couldn't get it to cooperate, so for now just unblocking that specific IP address seems to do the trick.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I add navigation dots to my slider?

I've been experimenting with my slider and I managed to make it slide automatically. However, the issue is that there is no option to manually navigate through the slides. I am looking to add navigation dots at the bottom so users can easily switch be ...

Center the text within a span element in an inline-block container

I'm currently working on a website design that features a flat aesthetic. I have a header at the top and two blocks of different colors placed side by side underneath it. Initially, I attempted to use float left and right for positioning but was recom ...

A guide to spinning an image in every direction with CSS

I'm working on rotating an image in all directions using CSS and Vue.js. To demonstrate this, I have created a CodePen with the necessary code below. <div id="app"> <v-app id="inspire"> <div class="text-xs-center image-rotation" ...

Ways to retrieve base64 encoded information from an image within an HTML document

On my registration form, users have the option to select an avatar from 2 choices: Select a default avatar Upload their own custom avatar This is how I have implemented it in my HTML page. <img id="preview" src="img/default_1.png"> The chosen av ...

Navigate through the items in my subnavbar by scrolling the content

HTML Code <div id="subnavigation"> <?php $verbindung = mysql_connect("host", "user" , "pw") or die("Verbindung zur Datenbank konnte nicht hergestellt werden"); mysql_select_db("db") or die ("Datenbank konnte nicht ausgewählt w ...

What could be causing the search function of the datatable to be hidden?

I am experiencing some difficulties with the code I have. My goal is to incorporate search functionality and pagination into my table. Unfortunately, it does not seem to be working as expected. Below is a snippet of the script located in the header section ...

What is another option for object-fit: cover?

Is there a way to resize an image on my webpage while maintaining its aspect ratio based on the screen size? I want the smaller dimension (width or height) to fit exactly within the element, with the larger dimension overflowing. I came across the objec ...

Choose the specific Element by its dynamicID in JQuery

Just starting out with Jquery and I have a specific task in mind. In my HTML page, I have elements with IDs generated by concatenating a string variable. My goal is to use JQuery to select the element with this dynamically generated ID. See below for more ...

Tips on styling HTML using a query value in string format

When using ASP.NET razor and SQL Server 2008 R2, I have a local variable declared in the following manner: var tsmMtd = db.QueryValue(" SELECT b.Name, SUM(subtotal) totalSUM FROM DR_TRANS a INNER JOIN Staff b ON a.Salesno = b.Staffno WHER ...

Implementing CSS Media Print, tables elegantly transition to a fresh page

I am encountering a challenge when it comes to printing my dynamic table along with some preceding text. It seems that sometimes the table begins on a new page, resulting in the header test being isolated on the first page and only displaying the table on ...

Enhancing user interfaces with jQuery by updating DOM elements

Can anyone help me figure out how to update a webpage so it functions as a report that multiple people can contribute to? I'm using forms to collect data and want it to instantly display under the correct category headings. Currently, I'm using j ...

What is the best way to display text outside of the current div container?

When I include the "Y" in the code snippet below, $title1 and $title2 are positioned outside of the div and centered against the width of the page. However, without the "Y", the text shifts up and aligns with the address class instead. It's puzzling w ...

CSS layout: The full-width header should align its left margin with the centered content-div

Can someone help me out with a solution to my problem? My page has a 1040px centered div for content, menu, and footer. I want the header image to align with the left margin of the content div and expand towards the right side for higher screen resolutio ...

Troubleshooting a unique CSS problem on an Android PhoneGap

We are currently working on an Android application using PhoneGap, HTML, CSS, and jQuery Mobile. After compiling the application in Eclipse, everything seems to work correctly. However, I am facing an issue where my CSS styles are not updating when recompi ...

Having trouble getting the JavaScript function to run when clicking a button inside a div or form?

Hey there, so I've got this scenario where I have a button nestled within a div. Take a look at the HTML snippet below: <div class="row"> <button type="button" id="submit">Send</button> </div> Prior to this button, there ...

Setting a radio button as default based on a variable value can be accomplished by following a few

I am working with 2 radio buttons and I need to dynamically check one based on a variable value. <input type="radio" name="team" id="team_7" value="7"> <input type="radio" name="team" id="team_8" value="8"> The variable number is set dependin ...

displaying outcomes as 'Indefinite' rather than the anticipated result in the input field

I need to automatically populate values into 4 text fields based on the input value entered by the user. When the user exits the input field, a function called getcredentials() is triggered. This function, in turn, executes Python code that retrieves the r ...

Tips on linking a condition-reaction to document.querySelector

I am struggling to connect the condition-reactions to the input id of passid. I am unsure where to place the document.querySelector() method in order to link the indexed conditions correctly. Below is the code snippet: <!doctype html> <html> ...

Minimize the width to display a scrollbar

Check out this page: where you'll find the same code snippet displayed twice - once through GitHub Gist embedding and the second using Jekyll's internal syntax highlighter Rouge. I'm currently working on styling the second code snippet to m ...

What are the steps to developing a responsive tile using HTML and CSS?

I am exploring the functionalities of CSS and responsive design. To better understand how it works, I created a simple example which can be accessed here. This demonstration showcases a basic tile template. My goal is to display my tiles in 2, 3, 4, or m ...