"The art of communication: Websockets bridging the cross-domain

Currently, I am in the process of creating two web applications:

  • The core application, developed using Java with Vert.x, is responsible for receiving data from various other apps and sending it to the client.
  • The client application, built using PHP/JS, is designed to display the data received from the core.

During development, both applications were hosted on the same computer. I used "ws:\\localhost:9090" to establish a connection between the client and the core without any issues.

However, when I attempted to replace 'localhost' with my IP Address today, I encountered some difficulties.

I suspect that the issue may be related to the fact that the client is not in the same domain as the core. How can I address this problem?

Any suggestions or ideas would be greatly appreciated!

Here is a code example (based on sample code, not actual code):

Answer №1

Absolutely, Websocket has the capability to work across different domains, but you must establish a handshake to make it happen. To better understand this process, I recommend checking out: http://en.wikipedia.org/wiki/WebSockets for an illustration of how handshakes are conducted.

Another insightful resource that may address similar concerns is: Web sockets make ajax/CORS obsolete?

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

Focusing on the combination of Phonegap, Angular JS, and Onsen for app development

We are working on developing an app using PhoneGap, Angular JS, and Onsen. One issue we are facing is that we are unable to center the header in a modal. The code snippet is provided below: <ons-modal var="modalVariable"> <ons-navigator var"de ...

Obtaining MIME-TYPE from a Base 64 String: A Handy Guide

After receiving a base64 encoded string from the backend, I am decoding it in Javascript to display it on the browser. The content of this string could be any type of file such as .pdf, .img, .docx, .zip, etc. The base64 string I have does not contain th ...

The use of PUPPETEER_DOWNLOAD_HOST has been phased out. It is recommended to use PUPPETEER_DOWNLOAD_BASE_URL moving forward. / Puppeteer

Trying to install puppeteer, I followed the installation guide. However, after a few seconds, I encountered this error: .../node_modules/puppeteer postinstall$ node install.mjs │ PUPPETEER_DOWNLOAD_HOST is deprecated. Use PUPPETEER_DOWNLOAD_BASE_URL ins ...

Fastify endpoint failing to respond to designated URL

Within my code, there is a router setup: fastify.get('/:link', (req, reply) => { req.params.url = req.host+req.url; reply.view("template.ejs",req.params); }); I am trying to capture URLs and process them in the template. All URLs are ...

Is there a way for me to make the login button redirect to the Dashboard?

I'm currently working on a piece of code where I need to implement some form of validation when the user clicks on the sign-in button. Specifically, I want to ensure that both the username and password fields are not left empty. If this condition is m ...

The response from Axios in NodeJs is displaying incorrect encoding

Having some trouble executing a REST call using Axios and receiving an unexpected response. try { const response = await axios.get("https://api.predic8.de/shop/products/"); console.log(response.data); } catch (error) { console.log(`[Error] -> ...

Error in Winston: Unable to determine the length of undefined property

I encountered an issue with my Winston Transport in the express backend of my MERN app. The error message reads: error: uncaughtException: Cannot read property 'length' of undefined TypeError: Cannot read property 'length' of undefi ...

Generating forms dynamically using JSON data

Currently, I'm using three nested ng-repeat directives to display multiple questions and their corresponding answers. Everything is displaying correctly so far, but now I need to create a form to save the answers. What would be the best approach to ac ...

Creating an HTML return statement to specifically target and extract a certain string while disregarding additional data

Looking for a solution to trim a long string returned by a webpage, while ensuring essential data is not removed. Counting characters is not feasible due to the varying length of the return. The return format is as follows: GET /New%20Messenger&subti ...

Switch between Fixed and Relative positions as you scroll

Just a small adjustment is needed to get it working... I need to toggle between fixed and relative positioning. JSFiddle Link $(window).on('scroll', function() { ($(window).scrollTop() > 50) ? ($('.me').addClass('fix ...

Tips for refreshing jQuery to ensure it functions smoothly for subsequent tasks

I am facing an issue with running a second process under JQuery, as shown in the code snippet below: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body> <script type=" ...

Having trouble getting a new input box to be added when clicking with AngularJS?

I am facing an issue with adding dynamic form fields to the database using PHP. I have utilized angular for this purpose, but only the last form field is getting inserted into the database. To address this, I attempted using arrays and loops to increment a ...

Having difficulty executing method for android:onClick

I recently developed a new activity named BankAccountActivity. Then, I attempted to launch this activity from my main activity upon clicking a button using the following code snippet: public void AddAccount(View V){ Intent intent = new Intent(context, ...

Updating elements across multiple arrays within a single document in MongoDB efficiently

I've encountered an issue while trying to update elements of multiple arrays using $push with comma separated values. When I attempt to include both arrays in the update like this, it results in an error. How can I achieve this? var conditions = { so ...

Encountering difficulties reaching $refs within component method

Trying to access a ref defined within a template when an element is clicked. Here's the HTML: <!DOCTYPE html> <html lang="en"> <head> <script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protectio ...

Angular sending information from one page and retrieving it on another

The reportForm page allows users to input information and submit it to create a report. reportData = { headline: $scope.headline, fromDate: $scope.fldFromDate, toDate: $scope.fldToDate, whatever: $scope.whatever } $http.post(reportUrl + $scope.repor ...

How to play two audio files at the same time on iOS Safari

I encountered a unique challenge in Javascript when attempting to play two audio files simultaneously on iOS Safari. One file is the voice script, while the other serves as background sound playing on loop. The code snippet I utilized for this task is as f ...

Is there a way to create a loop that continues running depending on the input provided by the user?

In one of my classes, I've been tasked with creating a simple program where a user can input the weight of a package, and the program will then calculate and display the shipping price based on that weight. Although not mandatory for the assignment, I ...

Having trouble accessing JavaScript Form Elements through Form Variable

For username validation in a form using JavaScript, I'm attempting to access the Label tag within the Form tag. If the Regex matches, then display an error in the Label; otherwise, hide it. However, when I try to modify the text in the text field, I e ...

Creating image galleries with HTML and Javascript loop through the drawImage function to display multiple

I'm currently working on developing a card game using HTML5 canvas, and I've come across an issue with the drawImage function when used inside a loop. It seems like there might be a problem related to closures, but I'm not entirely sure how ...