Connect to Socket.io


#1

I was wondering if it is possible to connect a processing sketch using the websockets library to socket.io. I tried it and got an error.


#2

Dan Shiffman did a video series on this. If that doesn’t help, could you describe what you’re trying to accomplish? Post your code and the error you’re getting.


#3

I’m trying to get a processing websocket server to read and print messages sent over the example socket.io server:
https://github.com/socketio/chat-example

Here is my code:

import websockets.*;

WebsocketClient w;

void setup() {
 size(200,200);
 w = new WebsocketClient(this, "ws://localhost:3000");
}

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

And here is my error:

[Animation Thread] INFO org.eclipse.jetty.util.log - Logging initialized @1855ms
[WebSocketClient@48536915-28] WARN org.eclipse.jetty.websocket.client.io.UpgradeConnection - read - EOF Reached
onError(EOFException: Reading WebSocket Upgrade response)
java.io.EOFException: Reading WebSocket Upgrade response
	at org.eclipse.jetty.websocket.client.io.UpgradeConnection.read(UpgradeConnection.java:267)
	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)


#4

Were you able to resolve your problem?

I browsed previous websockets discussion on the old forum:

but wasn’t sure if they were relevant to your issue.

Forum members with websockets experience might be found in previous threads here:

https://discourse.processing.org/search?q=websockets


#5

I haven’t been able to fix it yet, I have been working on other things. I wasn’t able to find anything easily on the old forum. I will have to dig deeper. Thanks!


#6

Update: I tested with ws, and my everything worked fine. It must have something to do with socket.io


#7

Another update: Changing the Url has made it possible to receive messages, although they are in weird formats. I changed the url to “ws://localhost:3000/socket.io/?EIO=3&transport=websocket”. Sending also doesn’t work.