Dear Community User! We are updating our platform to a new system.
Read more: Important information on the platform change.

cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

WebSocket server

WebSocket server

japikas
Established Member

Hi,

My intention is to streaam real-time data to my web UI integrated with the CtrlX Core dashboard. I have an UDP server implemented in Node.js to collect data from external sensor, and web-server cloned from the go.hello sample.

I have a Node.js WebSocket server implemented in the same snap application with the UDP server. It's working on my own computer w/o snap. The problem is that I'm unable to allow access to the WebSocket server, even if I know how to enable access to the UDP server. From the log file I can see that the WebSocket server is running, but not accessible. Propably something wrong with my config files.

I wonder if there's any example available how to implement WebSocket server, so that I could compare my configurations.

8 REPLIES 8

japikas
Established Member

It's very useful to ask questions here. First I struggle for days, and after asking I manage to figure out the problem within an hour... 😊

As usual, the problem was in own code. I did some changes after testing on own computer, which caused it not to work properly. Now it's working and case closed.

What my App does? Collects data from UDP socket server and USB serial port simultaneously. Synchronizes the data and provides as live-stream over WebSocket. A different snap app implements web server to host a web page to render the data in real-time chart.

japikas
Established Member

Not fully solved yet.

The WebSocket server provides the data over insecure ws connection. It's accepted by browser when loading html/js file from local file system of the developing computer. When the html page is hosted by the go-server in CtrlX Core, it's provided always over secure https connection, and browser does not accept insecure ws anymore, but requires secure connection for WebSocket as well.

No the question under investigation is how to do that, and how to bind it with the build-in https server of the Core.

nickH
Community Moderator
Community Moderator

Hi, 

I think you want to bind behind our reverse proxy on the ctrlX CORE. You can use the package-assets interface to provide additional information of your app (e.g. binding) to the ctrlX OS. Please see this documentation on how to do that. 

Best regards, 

Nick

japikas
Established Member

Thanks! Got the reverse proxy working. Now the secure part of connection is taken care by the proxy, even if my app itself is non-secure.

For information to other folks, here's what I did:

Added following in the snap/snapcraft.yaml file:

parts:
[...]
  configs:
    source: ./configs
    plugin: dump
    organize:
      'package-assets/*': package-assets/${SNAPCRAFT_PROJECT_NAME}/
slots:
  package-assets:
    interface: content
    content: package-assets
    source:
      read:
      - $SNAP/package-assets/${SNAPCRAFT_PROJECT_NAME}

And created file configs/package-assets/my-app.package-manifest.json

{
    "version": "0.0.0",
    "id": "my-app",
    "services": {
        "proxyMapping": [
            {
                "name": "my-app.ws",
                "url": "/my-app",
                "binding": ":8080",
                "restricted": [
                ] 
            }
        ]
    }
}

So, now I can open secure WebSocket connection to 'wss://my-host/my-app' which is redirected to my-app bound to port 8080 in this case.

However, I can still open non-secure WebSocket connection from external host directly to my app 'ws://my-host:8080'.

How do I prevent that? Some firewall settings needed?

nickH
Community Moderator
Community Moderator

I see three possibility how you can solve this:

  1. Use the ctrlX CORE - Firewall app to refuse any connection from external directly to this port. 
  2. You could use Unix sockets from your web server. The samples in the SDK already do this (see: https://github.com/boschrexroth/ctrlx-automation-sdk/tree/main/samples-go/hello.webserver).  The web server of your application has to bind against a Unix Domain Socket. Most web server frameworks already support this functionality. This is also described in the documentation
  3. You could also tell your webserver to only listen to "127.0.0.1:1234". I tried this with the same hello.webserver example and modified it a little bit. This sample uses the net go package (see also: this part of the documentation of the net go package).
    2023-03-10_13h14_01.png

japikas
Established Member

It's not a web server but WebSocket server, thus solution 2 and 3 needs a bit more tweaking, as the instructions does not cover that case. I do have a separate web server app running in parallel with no problems.

It seems to be possible to bind WebSocket server to unix domain socket, but then the path is slightly different, something like: 

"ws+unix:///path/server.sock"

 

WEI_You
Established Member

I have the same problem,

I want to built a app,it can provide socket to other device,and also have a webUI page which can give some data for myself(Like sample HMI functiom),If you have any idea or solution,we can discuss.I can do it in my PC but I don't know how to built it to a app which can run in CtrlX core

Best regards,

nickH
Community Moderator
Community Moderator

Please have a look at the samples in the SDK. There are already samples which show you how to do this (see: https://github.com/boschrexroth/ctrlx-automation-sdk/tree/main/samples-go/hello.webserver).  Please also have a look into our documentation. In this section you will find information on how to bind your webserver (unix socket) behind our reverse proxy. 

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist