Processing to Socket.Io on Unubo


#1

Hi, I have a socket.io app hosted on a website called Unubo (paint.unubo.cloud), and when I try to connect to it using the Websockets library for processing, I get this error:

onError(UpgradeException: Didn't switch protocols, expected status <101>, but got <301>)
org.eclipse.jetty.websocket.api.UpgradeException: Didn't switch protocols, expected status <101>, but got <301>
	at org.eclipse.jetty.websocket.client.io.UpgradeConnection.validateResponse(UpgradeConnection.java:352)
	at org.eclipse.jetty.websocket.client.io.UpgradeConnection.read(UpgradeConnection.java:280)
	at org.eclipse.jetty.websocket.client.io.UpgradeConnection.onFillable(UpgradeConnection.java:196)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:261)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
	at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:75)
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:213)
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:147)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
	at java.lang.Thread.run(Thread.java:748)

Does anybody have any idea what this means, or how to fix it?

Here is my processing code:

import websockets.*;

WebsocketClient w;

void setup() {
 size(300,300);
 w = new WebsocketClient(this, "ws://paint.unubo.cloud/socket.io/?EIO=3&transport=websocket");
}

void draw() {
  
}

void keyPressed() {
 w.sendMessage("42[\"chat message\",\"hello from processing\"]"); 
}

void webSocketEvent(String msg) {
 println(msg); 
}

and my server code is here
https://github.com/Quillbert/net-paint


#2

Hi, does it work if you replace ws: with wss:? https://stackoverflow.com/questions/46557485/difference-between-ws-and-wss


#3

If I change it to wss I get this error:

onError(IOException: Cannot init SSL)
java.io.IOException: Cannot init SSL
	at org.eclipse.jetty.websocket.client.io.WebSocketClientSelectorManager.newConnection(WebSocketClientSelectorManager.java:98)
	at org.eclipse.jetty.io.ManagedSelector.createEndPoint(ManagedSelector.java:411)
	at org.eclipse.jetty.io.ManagedSelector.access$1600(ManagedSelector.java:56)
	at org.eclipse.jetty.io.ManagedSelector$CreateEndPoint.run(ManagedSelector.java:587)
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:213)
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.execute(ExecuteProduceConsume.java:101)
	at org.eclipse.jetty.io.ManagedSelector.run(ManagedSelector.java:136)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
	at java.lang.Thread.run(Thread.java:748)
onError(IOException: Cannot init SSL)
java.io.IOException: Cannot init SSL
	at org.eclipse.jetty.websocket.client.io.WebSocketClientSelectorManager.newConnection(WebSocketClientSelectorManager.java:98)
	at org.eclipse.jetty.io.ManagedSelector.createEndPoint(ManagedSelector.java:411)
	at org.eclipse.jetty.io.ManagedSelector.access$1600(ManagedSelector.java:56)
	at org.eclipse.jetty.io.ManagedSelector$CreateEndPoint.run(ManagedSelector.java:587)
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:213)
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.execute(ExecuteProduceConsume.java:101)
	at org.eclipse.jetty.io.ManagedSelector.run(ManagedSelector.java:136)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
	at java.lang.Thread.run(Thread.java:748)


#4

Not sure what’s going on. The client is expecting a 101 code (which means things went ok) but it receives a 301 code (which is a redirect to a different address). I don’t know why the redirect, nor to what new address it’s being redirected to.


#5

I just found out that it was the wss thing, but the library doesn’t support ssl, so I will have to find another library. I will probably use too tall nate’s java library.