# Websockets not working with java version

**URL:** https://discourse.processing.org/t/websockets-not-working-with-java-version/9518
**Category:** Libraries
**Created:** [March 21, 2019, 11:10pm UTC](https://discourse.processing.org/t/websockets-not-working-with-java-version/9518 "2019-03-21T23:10:08Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Quillbert1](https://avatars.discourse-cdn.com/v4/letter/q/f475e1/32.png) [@Quillbert1](https://discourse.processing.org/u/Quillbert1)
#### Post date: [March 21, 2019, 11:10pm UTC](https://discourse.processing.org/t/websockets-not-working-with-java-version/9518/1 "2019-03-21T23:10:09Z")

</div>

I have a networked paint app hosted at [paint.unubo.cloud](http://paint.unubo.cloud). I am using [socket.io](http://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](https://github.com/TooTallNate/Java-WebSocket)). Here is the client code:

```auto
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:

[https://stackoverflow.com/questions/55263235/websockets-disconnecting-with-code-1-with-too-tall-nate-java-library](https://stackoverflow.com/questions/55263235/websockets-disconnecting-with-code-1-with-too-tall-nate-java-library)

---

<div class="post-metadata">

### Author: ![Quillbert1](https://avatars.discourse-cdn.com/v4/letter/q/f475e1/32.png) [@Quillbert1](https://discourse.processing.org/u/Quillbert1)
#### Post date: [March 23, 2019, 2:06am UTC](https://discourse.processing.org/t/websockets-not-working-with-java-version/9518/2 "2019-03-23T02:06:47Z")

</div>

Does anyone at least know what it means when websockets close with code -1?

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [March 23, 2019, 4:07am UTC](https://discourse.processing.org/t/websockets-not-working-with-java-version/9518/3 "2019-03-23T04:07:08Z")

</div>

just curious why you use

```auto
wss://_host_/socket.io/?EIO=3&transport=websocket

```

where you get that example from?

and not like in the example  
[https://github.com/TooTallNate/Java-WebSocket/blob/master/src/main/example/SSLClientExample.java](https://github.com/TooTallNate/Java-WebSocket/blob/master/src/main/example/SSLClientExample.java) ,

```auto
wss://_host_:8887

```

using a PORT

---

<div class="post-metadata">

### Author: ![Quillbert1](https://avatars.discourse-cdn.com/v4/letter/q/f475e1/32.png) [@Quillbert1](https://discourse.processing.org/u/Quillbert1)
#### Post date: [March 23, 2019, 4:45am UTC](https://discourse.processing.org/t/websockets-not-working-with-java-version/9518/4 "2019-03-23T04:45:25Z")

</div>

I was using the processing websockets library, and in the github issues for that, it tells you to use that to connect to a [socket.io](http://socket.io) server. I switched because that library didn’t support wss. Also, I don’t know the port number. It’s like heroku.
