# WebSocket Client

**URL:** <https://forum.inductiveautomation.com/t/websocket-client/44447>\
**Category:** Ignition\
**Tags:** ignition81, vision, scripting\
**Created:** [March 14, 2021, 8:48pm UTC](https://forum.inductiveautomation.com/t/websocket-client/44447 "2021-03-14T20:48:08Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacob](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@jacob](https://forum.inductiveautomation.com/u/jacob)\
**Post date:** [March 14, 2021, 8:48pm UTC](https://forum.inductiveautomation.com/t/websocket-client/44447/1 "2021-03-14T20:48:08Z")

</div>

Hi.  
I have temperature sensors that have an API using WebSocket protocol (wss).  
I imported the library [https://pypi.org/project/websocket-client/](https://pypi.org/project/websocket-client/) to create a WebSocket client.

My script for establishing a connection:

```auto
import websocket

ws = websocket.WebSocket()
ws.connect("wss://echo.websocket.org")
ws.send("Hello, Server")
print(ws.recv())

```

If I use “ws://” connection created, but if I use “wss://” i get error:

```auto
Traceback (most recent call last):
  File "<input>", line 4, in <module>
  File "C:\Users\User\.ignition\cache\gwlocalhost_8088\C0\pylib\websocket\_core.py", line 248, in connect
    self.sock, addrs = connect(url, self.sock_opt, proxy_info(**options),
  File "C:\Users\User\.ignition\cache\gwlocalhost_8088\C0\pylib\websocket\_http.py", line 126, in connect
    sock = _ssl_socket(sock, options.sslopt, hostname)
  File "C:\Users\User\.ignition\cache\gwlocalhost_8088\C0\pylib\websocket\_http.py", line 266, in _ssl_socket
    sock = ssl.wrap_socket(sock, **sslopt)
  File "C:\Users\User\.ignition\cache\gwlocalhost_8088\C0\pylib\_socket.py", line 382, in handle_exception
    return method_or_function(*args, **kwargs)
  File "C:\Users\User\.ignition\cache\gwlocalhost_8088\C0\pylib\_socket.py", line 382, in handle_exception
    return method_or_function(*args, **kwargs)
  File "C:\Users\User\.ignition\cache\gwlocalhost_8088\C0\pylib\ssl.py", line 904, in wrap_socket
    return SSLSocket(
  File "C:\Users\User\.ignition\cache\gwlocalhost_8088\C0\pylib\ssl.py", line 575, in __init__
    self.do_handshake()
  File "C:\Users\User\.ignition\cache\gwlocalhost_8088\C0\pylib\ssl.py", line 691, in do_handshake
    self._sock._handle_channel_future(self._handshake_future, "SSL handshake")
  File "C:\Users\User\.ignition\cache\gwlocalhost_8088\C0\pylib\_socket.py", line 384, in handle_exception
    raise _map_exception(jlx)
_socket.SSLError: [Errno 1] certificate verify failed (java.security.cert.CertificateException: certificate verify failed)

```

Please tell me what I can do to fix this.  
Maybe there are some other tools for working with websocket in Ignition.  
On the forum I read that you can use the jetty java library, But I never worked with this.  
I would be grateful for any help.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 14, 2021, 8:57pm UTC](https://forum.inductiveautomation.com/t/websocket-client/44447/2 "2021-03-14T20:57:31Z")

</div>

It’s failing because `wss://` (vs `ws://`) means use SSL/TLS, and it appears whatever server you’re connected to doesn’t have a trustworthy certificate.

Do you know if it’s signed by a real CA or if it’s an internal CA or self-signed cert?

You should be able to tell Ignition to trust it by adding it to the supplemental certs folder and restarting the gateway. [https://docs.inductiveautomation.com/display/DOC81/Adding+Security+Certificates+into+Keystores](https://docs.inductiveautomation.com/display/DOC81/Adding+Security+Certificates+into+Keystores)

---

<div class="post-metadata">

**Author:** ![jacob](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@jacob](https://forum.inductiveautomation.com/u/jacob)\
**Post date:** [March 14, 2021, 9:11pm UTC](https://forum.inductiveautomation.com/t/websocket-client/44447/3 "2021-03-14T21:11:52Z")

</div>

I dont know if it’s signed by a real CA or if it’s an internal CA or self-signed cert.  
But if i execute this script in cmd it works.

Thanks Kevin  
I will try to get a certificate of trust, and do as you said. I’ll let you know if everything works out.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 14, 2021, 9:15pm UTC](https://forum.inductiveautomation.com/t/websocket-client/44447/4 "2021-03-14T21:15:20Z")

</div>

If you’re really getting that error for `wss://echo.websocket.org` and not just your sensor then I’m not really sure why it’s not working because that should be a real cert from Lets Encrypt…

Let us know if adding the certificate makes it work or not either way.

---

<div class="post-metadata">

**Author:** ![jacob](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@jacob](https://forum.inductiveautomation.com/u/jacob)\
**Post date:** [March 15, 2021, 12:51pm UTC](https://forum.inductiveautomation.com/t/websocket-client/44447/5 "2021-03-15T12:51:25Z")

</div>

Hi.  
I found out that the sensors I have are using Lets Encrypt to generate https certificates.  
I getting that error for wss://echo.websocket.org and not just my sensor.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 15, 2021, 4:40pm UTC](https://forum.inductiveautomation.com/t/websocket-client/44447/6 "2021-03-15T16:40:40Z")

</div>

You’re basically on your own re: documentation, but the Java HTTP client available via the `system.net.httpClient` scripting function has the ability to connect to websockets; it’d be something like:  
`system.net.httpClient().javaClient.newWebSocketBuilder()`, at which point you’ll want to refer to the JDK for documention.

---

<div class="post-metadata">

**Author:** ![jacob](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@jacob](https://forum.inductiveautomation.com/u/jacob)\
**Post date:** [March 25, 2021, 2:01pm UTC](https://forum.inductiveautomation.com/t/websocket-client/44447/7 "2021-03-25T14:01:31Z")

</div>

Hi.  
Thanks for the answer, Paul.  
I figured out the Jython implementation using `system.net.httpClient (). JavaClient.newWebSocketBuilder ()`.  
I wrote a script like this:

```auto

from java.net.http import HttpClient;
from java.net.http import WebSocket;
from java.net import URI;

class listener(WebSocket.Listener):

	def onOpen(self, websocket):
		#print websocket.getSubprotocol()
		print "Event OnOpen"
		#print type(websocket)
		
		websocket.sendText("Hi", True)
		print "Sended"
		websocket.request(1)

	def onText(self, websocket, data, last):
		print "Event OnText"
		print "Response from server: " + data
		websocket.request(1)
		
client = HttpClient.newHttpClient()

client.newWebSocketBuilder().buildAsync(URI.create("ws://echo.websocket.org"), listener());

```

If I execute this script in cmd it works.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/4/54b55e6d3789a37f8db97ce1864e99cb644d0ad0.png)

But if I execute this script in Ignition Script Console I get an error:

```auto
__main__ :6: RuntimeWarning: PyTableCode.call caught a Throwable that is not an Exception:
java.lang.VerifyError: (class: org/python/proxies/ __main__ $listener$13, method: super__onText signature: (Ljava/net/http/WebSocket;Ljava/lang/CharSequence;Z)Ljava/util/concurrent/CompletionStage;) Illegal use of nonvirtual function call
Jython internals might be in a bad state now that can cause deadlocks later on.
See http://bugs.jython.org/issue2536 for details.
Java Traceback:
Traceback (most recent call last):
  File "<input>", line 6, in <module>
java.lang.VerifyError: (class: org/python/proxies/ __main__ $listener$13, method: super__onText signature: (Ljava/net/http/WebSocket;Ljava/lang/CharSequence;Z)Ljava/util/concurrent/CompletionStage;) Illegal use of nonvirtual function call

	at java.base/java.lang.Class.getDeclaredMethods0(Native Method)

	at java.base/java.lang.Class.privateGetDeclaredMethods(Unknown Source)

	at java.base/java.lang.Class.privateGetPublicMethods(Unknown Source)

	at java.base/java.lang.Class.getMethods(Unknown Source)

	at org.python.core.PyJavaType.init(PyJavaType.java:291)

	at org.python.core.PyType.createType(PyType.java:1573)

	at org.python.core.PyType.addFromClass(PyType.java:1508)

	at org.python.core.PyType.fromClass(PyType.java:1609)

	at org.python.core.PyType.setupProxy(PyType.java:827)

	at org.python.core.PyType.newType(PyType.java:257)

	at org.python.core.PyType.type ___new__ (PyType.java:202)

	at org.python.core.PyType$exposed ___new__.new_impl(Unknown Source)

	at org.python.core.PyType.invokeNew(PyType.java:636)

	at org.python.core.PyType.type ___call__ (PyType.java:1873)

	at org.python.core.PyType. __call__ (PyType.java:1863)

	at org.python.core.PyObject. __call__ (PyObject.java:515)

	at org.python.core.Py.makeClass(Py.java:2107)

	at org.python.core.Py.makeClass(Py.java:2068)

	at org.python.core.Py.makeClass(Py.java:2060)

	at org.python.pycode._pyx65.f$0(<input>:24)

	at org.python.pycode._pyx65.call_function(<input>)

	at org.python.core.PyTableCode.call(PyTableCode.java:171)

	at org.python.core.PyCode.call(PyCode.java:18)

	at org.python.core.Py.runCode(Py.java:1614)

	at org.python.core.Py.exec(Py.java:1658)

	at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:276)

	at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:131)

	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:605)

	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:593)

	at java.desktop/javax.swing.SwingWorker$1.call(Unknown Source)

	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)

	at java.desktop/javax.swing.SwingWorker.run(Unknown Source)

	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

	at java.base/java.lang.Thread.run(Unknown Source)

java.lang.VerifyError: java.lang.VerifyError: (class: org/python/proxies/ __main__ $listener$13, method: super__onText signature: (Ljava/net/http/WebSocket;Ljava/lang/CharSequence;Z)Ljava/util/concurrent/CompletionStage;) Illegal use of nonvirtual function call

	at org.python.core.Py.JavaError(Py.java:552)

	at org.python.core.PyTableCode.call(PyTableCode.java:180)

	at org.python.core.PyCode.call(PyCode.java:18)

	at org.python.core.Py.runCode(Py.java:1614)

	at org.python.core.Py.exec(Py.java:1658)

	at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:276)

	at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:131)

	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:605)

	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:593)

	at java.desktop/javax.swing.SwingWorker$1.call(Unknown Source)

	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)

	at java.desktop/javax.swing.SwingWorker.run(Unknown Source)

	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

	at java.base/java.lang.Thread.run(Unknown Source)

Caused by: java.lang.VerifyError: (class: org/python/proxies/ __main__ $listener$13, method: super__onText signature: (Ljava/net/http/WebSocket;Ljava/lang/CharSequence;Z)Ljava/util/concurrent/CompletionStage;) Illegal use of nonvirtual function call

	at java.base/java.lang.Class.getDeclaredMethods0(Native Method)

	at java.base/java.lang.Class.privateGetDeclaredMethods(Unknown Source)

	at java.base/java.lang.Class.privateGetPublicMethods(Unknown Source)

	at java.base/java.lang.Class.getMethods(Unknown Source)

	at org.python.core.PyJavaType.init(PyJavaType.java:291)

	at org.python.core.PyType.createType(PyType.java:1573)

	at org.python.core.PyType.addFromClass(PyType.java:1508)

	at org.python.core.PyType.fromClass(PyType.java:1609)

	at org.python.core.PyType.setupProxy(PyType.java:827)

	at org.python.core.PyType.newType(PyType.java:257)

	at org.python.core.PyType.type ___new__ (PyType.java:202)

	at org.python.core.PyType$exposed ___new__.new_impl(Unknown Source)

	at org.python.core.PyType.invokeNew(PyType.java:636)

	at org.python.core.PyType.type ___call__ (PyType.java:1873)

	at org.python.core.PyType. __call__ (PyType.java:1863)

	at org.python.core.PyObject. __call__ (PyObject.java:515)

	at org.python.core.Py.makeClass(Py.java:2107)

	at org.python.core.Py.makeClass(Py.java:2068)

	at org.python.core.Py.makeClass(Py.java:2060)

	at org.python.pycode._pyx65.f$0(<input>:24)

	at org.python.pycode._pyx65.call_function(<input>)

	at org.python.core.PyTableCode.call(PyTableCode.java:171)

	... 13 more

Traceback (most recent call last):
  File "<input>", line 6, in <module>
java.lang.VerifyError: (class: org/python/proxies/ __main__ $listener$13, method: super__onText signature: (Ljava/net/http/WebSocket;Ljava/lang/CharSequence;Z)Ljava/util/concurrent/CompletionStage;) Illegal use of nonvirtual function call

	at java.base/java.lang.Class.getDeclaredMethods0(Native Method)

	at java.base/java.lang.Class.privateGetDeclaredMethods(Unknown Source)

	at java.base/java.lang.Class.privateGetPublicMethods(Unknown Source)

	at java.base/java.lang.Class.getMethods(Unknown Source)

	at org.python.core.PyJavaType.init(PyJavaType.java:291)

	at org.python.core.PyType.createType(PyType.java:1573)

	at org.python.core.PyType.addFromClass(PyType.java:1508)

	at org.python.core.PyType.fromClass(PyType.java:1609)

	at org.python.core.PyType.setupProxy(PyType.java:827)

	at org.python.core.PyType.newType(PyType.java:257)

	at org.python.core.PyType.type ___new__ (PyType.java:202)

	at org.python.core.PyType$exposed ___new__.new_impl(Unknown Source)

	at org.python.core.PyType.invokeNew(PyType.java:636)

	at org.python.core.PyType.type ___call__ (PyType.java:1873)

	at org.python.core.PyType. __call__ (PyType.java:1863)

	at org.python.core.PyObject. __call__ (PyObject.java:515)

	at org.python.core.Py.makeClass(Py.java:2107)

	at org.python.core.Py.makeClass(Py.java:2068)

	at org.python.core.Py.makeClass(Py.java:2060)

	at org.python.pycode._pyx65.f$0(<input>:24)

	at org.python.pycode._pyx65.call_function(<input>)

	at org.python.core.PyTableCode.call(PyTableCode.java:171)

	at org.python.core.PyCode.call(PyCode.java:18)

	at org.python.core.Py.runCode(Py.java:1614)

	at org.python.core.Py.exec(Py.java:1658)

	at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:276)

	at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:131)

	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:605)

	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:593)

	at java.desktop/javax.swing.SwingWorker$1.call(Unknown Source)

	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)

	at java.desktop/javax.swing.SwingWorker.run(Unknown Source)

	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

	at java.base/java.lang.Thread.run(Unknown Source)

java.lang.VerifyError: java.lang.VerifyError: (class: org/python/proxies/ __main__ $listener$13, method: super__onText signature: (Ljava/net/http/WebSocket;Ljava/lang/CharSequence;Z)Ljava/util/concurrent/CompletionStage;) Illegal use of nonvirtual function call

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 25, 2021, 3:46pm UTC](https://forum.inductiveautomation.com/t/websocket-client/44447/8 "2021-03-25T15:46:52Z")

</div>

At the end of your `onText` implementation, Jython is trying to automatically call the default implementation of `onText` from the interface…but Jython predates default/virtual methods on Java interfaces, so it appears to be causing some confusion in Jython’s internals. You could try manually inserting a call to the interface method? `return WebSocket.Listener.onText(self, websocket, data, last)` at the end of your `onText` call? Or try manually `return None` at the end of your impl, to try to prevent the default impl from being called.

---

<div class="post-metadata">

**Author:** ![jacob](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@jacob](https://forum.inductiveautomation.com/u/jacob)\
**Post date:** [March 28, 2021, 9:43am UTC](https://forum.inductiveautomation.com/t/websocket-client/44447/9 "2021-03-28T09:43:13Z")

</div>

Hi Paul.  
I don’t quite understand what I have to do.  
If I don’t define the onText method, the error is thrown as well.  
Could you explain to me in more detail what I can try to do?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 29, 2021, 4:34pm UTC](https://forum.inductiveautomation.com/t/websocket-client/44447/10 "2021-03-29T16:34:55Z")

</div>

Try manually inserting a `return None` at the end of your `onText` implementation. It looks like Jython is trying to automatically call the default method on the `Websocket.Listener` _interface_ (default methods on interfaces is a Java 8 change), and getting confused (probably because Jython predates Java 8 by a number of years).

IE:

```python
class listener(WebSocket.Listener):
	def onOpen(self, websocket):
		#print websocket.getSubprotocol()
		print "Event OnOpen"
		#print type(websocket)
		
		websocket.sendText("Hi", True)
		print "Sended"
		websocket.request(1)

	def onText(self, websocket, data, last):
		print "Event OnText"
		print "Response from server: " + data
		websocket.request(1)
		return None

```

---

<div class="post-metadata">

**Author:** ![jacob](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@jacob](https://forum.inductiveautomation.com/u/jacob)\
**Post date:** [March 30, 2021, 2:05pm UTC](https://forum.inductiveautomation.com/t/websocket-client/44447/11 "2021-03-30T14:05:47Z")

</div>

Hi.  
Thanks, Paul.  
OU.  
I’ve tried it, but it doesn’t work. (the same error occurs)  
The error occurs during initialization: `class listener (WebSocket.Listener):`  
and if I do not declare the onText () method, the error will remain

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 30, 2021, 4:27pm UTC](https://forum.inductiveautomation.com/t/websocket-client/44447/12 "2021-03-30T16:27:55Z")

</div>

It’s a Jython bug. [https://bugs.jython.org/issue2403](https://bugs.jython.org/issue2403)  
Unfortunately, I don’t think there’s any workaround you can do as an end user; we need to update Ignition’s Jython to 2.7.2. I’ve bumped the internal ticket for that effort in priority.

---

<div class="post-metadata">

**Author:** ![jacob](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@jacob](https://forum.inductiveautomation.com/u/jacob)\
**Post date:** [March 31, 2021, 10:05am UTC](https://forum.inductiveautomation.com/t/websocket-client/44447/13 "2021-03-31T10:05:18Z")

</div>

Clear.  
It’s a pity.  
Thanks for the help, Paul.  
We will wait for the update.)

---

<div class="post-metadata">

**Author:** ![nicholas.robinson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nicholas.robinson/32/22188_2.png) [@nicholas.robinson](https://forum.inductiveautomation.com/u/nicholas.robinson)\
**Post date:** [February 10, 2022, 5:06am UTC](https://forum.inductiveautomation.com/t/websocket-client/44447/14 "2022-02-10T05:06:50Z")

</div>

@jacob curious if you ever got this working.

Thanks,

Nick

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 10, 2022, 3:21pm UTC](https://forum.inductiveautomation.com/t/websocket-client/44447/15 "2022-02-10T15:21:51Z")

</div>

The linked bug with Jython should be fixed in 8.1.8, where we updated our bundled Jython to 2.7.2. The rest of Jacob’s code looked sound, at least at a first glance.

---

<div class="post-metadata">

**Author:** ![nicholas.robinson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nicholas.robinson/32/22188_2.png) [@nicholas.robinson](https://forum.inductiveautomation.com/u/nicholas.robinson)\
**Post date:** [February 10, 2022, 3:56pm UTC](https://forum.inductiveautomation.com/t/websocket-client/44447/16 "2022-02-10T15:56:30Z")

</div>

Cool, I plan on giving it a try today. Will share the results.

Cheers,

Nick

---

<div class="post-metadata">

**Author:** ![nicholas.robinson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nicholas.robinson/32/22188_2.png) [@nicholas.robinson](https://forum.inductiveautomation.com/u/nicholas.robinson)\
**Post date:** [February 18, 2022, 10:03pm UTC](https://forum.inductiveautomation.com/t/websocket-client/44447/17 "2022-02-18T22:03:56Z")

</div>

I finally got a chance to test this today but I'm getting stuck, the output from this:

```auto
client.newWebSocketBuilder().buildAsync(URI.create(baseUrl+"ws/v2/sql/execute"), listener())

```

Is this

> jdk.internal.net.http.common.MinimalFuture@6a28325[Completed exceptionally: java.lang.IllegalArgumentException: invalid URI scheme: https]

Of course not expecting anyone to solve this for me, just posting here in case anyone has experience they can share, or in case this helps someone down the line.

We are using and https url.

Thanks,

Nick

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 19, 2022, 2:03am UTC](https://forum.inductiveautomation.com/t/websocket-client/44447/18 "2022-02-19T02:03:57Z")

</div>

Try using “wss://“ instead of “https://“.

---

<div class="post-metadata">

**Author:** ![nicholas.robinson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nicholas.robinson/32/22188_2.png) [@nicholas.robinson](https://forum.inductiveautomation.com/u/nicholas.robinson)\
**Post date:** [February 21, 2022, 3:33am UTC](https://forum.inductiveautomation.com/t/websocket-client/44447/19 "2022-02-21T03:33:04Z")

</div>

That worked to fix that error. I have tested this API with the google web socket tested so I know its good.

At the end of the following code I get this message, I feel like I need to have something after the web socket builder that is currently not there. At present I never see the onOpen method executed.

> jdk.internal.net.http.common.MinimalFuture@59ff0c80[Not completed] (id=939)

```auto
# Login
r = c.post(baseUrl + "login", data=params)
authToken = r.text

queryParams = {
	"token": authToken,
	"stats": 5000,
	"sql": query,
	"live": False
}

class listener(WebSocket.Listener):
	def onOpen(self, websocket):
		print("Event OnOpen")
		websocket.sendText(queryParams, True)
		print "Sent"
		websocket.request(1)
	
	def onText(self, websocket, data, last):
		print "Event OnText"
		print "Response from server: " + data
		websocket.request(1)
		return None
		
uri = URI.create(baseUrl.replace("https", "wss") + "ws/v2/sql/execute") 		
client = HttpClient.newHttpClient()		
client.newWebSocketBuilder().buildAsync(uri, listener())

```

Thanks,

Nick

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 21, 2022, 1:12pm UTC](https://forum.inductiveautomation.com/t/websocket-client/44447/20 "2022-02-21T13:12:20Z")

</div>

You are discarding the return value from .buildAsync(). Don’t do that. You need it to .get() the finished websocket object.

[Next page](https://forum.inductiveautomation.com/t/websocket-client/44447.md?page=2)
