1

I have been exploring opcua, I have a simple opcua client and server application, for that I have used an package that was node-opcua, That time my server and client works fine.

What my task is, That I need to run the opcua client in the browser, for that opcua didn't provide any ways. So to that I get the opcua golang sample code from github, and I convert in into webAssembly. and read the converted golang code in the HTML file using the javascript fetch API/ Then I have run the simple HTML code to run the OPC UA client in the browser, I have given that html below

<html>  
    <head>
        <meta charset="utf-8"/>
        <script src="wasm_exec.js"></script>
        <script>
            const go = new Go();
            console.log(go);
            WebAssembly.instantiateStreaming(fetch("<filename>.wasm"), go.importObject).then((result) => {
                go.run(result.instance);
            });
        </script>
    </head>
    <body></body>
</html>

When I run that html code in my browser, it throws the error dial tcp 192.168.225.225:4840: Connection refused

To re produce that issue

  1. Click and copy the server side code.
  2. Click and copy the client side code.
  3. Install the golang on local machine.
  4. convert golang code to webAssembly run the command (GOOS=js GOARCH=wasm go build -o <filname>.wasm <filename>.go).
  5. Copy the above HTML code. and run that in the browser.

I tried following ways

  1. I used localhost as domain name in both client and server, that I got that error like could not resolve address localhost:4840
  2. Bind the hostname in 0.0.0.0 in the server side, and used localhost on the client side that time also I got the error like opcua: could not resolve address localhost:4840,
  3. Used my private IP in the both client and server side that time I got the error like dial tcp 192.168.1.220:4840: Connection refused.
  4. Instead of the my local machine server address, I have used to some public OPC-UA server address in my client application, that time also I got the error like dial tcp opc.tcp://opcuademo.sterfive.com:26543: Connection refused.

I need to run that OPC UA client in the browser, Let me know, if you know the answer to resolve the above errors, or is there any other approach to achive my task?

Bennison J
  • 414
  • 1
  • 12

1 Answers1

1

To the problem is that you can't use any BSD socket in the browser. The connection will be translate to websocket. But no opcua server supports Websocket as protocol. The best way is to add a opc client on your webserver. This client communicate with the client js code over websockets and send the values as json decoded format.

Schroeder
  • 749
  • 4
  • 10