I have a networked paint app hosted at paint.unubo.cloud. I am using socket.io for the networking. Whenever I run the app on a localhost, everything works just fine, but when I try to connect to the app on unubo, the socket client immediately closes with code -1. I am using Too Tall Nate’s Java Library (https://github.com/TooTallNate/Java-WebSocket). Here is the client code:
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
import java.net.URI;
Client client;
boolean isOpen = false;
int x = -50;
int y = -50;
public void setup() {
size(600, 600);
background(100);
fill(0);
try {
client = new Client(new URI("wss://paint.unubo.cloud/socket.io/?EIO=3&transport=websocket"));
client.connect();
}
catch(Exception e) {
println(e);
}
}
public void draw() {
ellipse(x, y, 10, 10);
}
public void mouseDragged() {
if (isOpen) {
client.send("42[\"message\",{\"x\":" + mouseX + ",\"y\":" + mouseY + "}]");
}
}
public void keyPressed() {
client.connect();
}
class Client extends WebSocketClient {
public Client(URI serverURI) {
super(serverURI);
}
public void onError(Exception e) {
println(e);
}
public void onClose(int reason, String details, boolean remote) {
println("Closed: " + reason + " " + details);
isOpen = false;
exit();
}
public void onOpen(ServerHandshake hs) {
println("Connected");
isOpen = true;
}
public void onMessage(String message) {
if (message.length() > 2 && message.substring(0, 2).equals("42")) {
String data = message.substring(13, message.length() - 1);
JSONObject json = JSONObject.parse(data);
println(json.toString());
x = json.getInt("x");
y = json.getInt("y");
ellipse(json.getInt("x"), json.getInt("y"), 10, 10);
}
}
}
Can anyone help?
Also posted on stack overflow: