Connect to Websocket Server from Processing

Hi All,

I've done a fair bit of looking around and I can't seem to find a working solution to connect to a Websocket server.

The server is hosted on another computer for which I have an ip address and port.

If I do ping [ipaddress] in terminal then it responds as expected.

The server is hosted in Python using Autobahn's implementation of Websocket.

I have very little experience with websockets and would appreciate some guidance.

Thanks, Charles

EDIT: This library seems to work unfortunately I when I try to connect I get the following error:

Library: https://github.com/alexandrainst/processing_websockets

Code:

    import websockets.*;

    WebsocketClient wsc;
    int now;
    boolean newEllipse;

    void setup(){
      size(200,200);

      newEllipse=true;

      wsc= new WebsocketClient(this, "ws:1--.1--.5.222:9000");
      now=millis();
    }

    void draw(){
      if(newEllipse){
        ellipse(random(width),random(height),10,10);
        newEllipse=false;
      }

      if(millis()>now+5000){
        wsc.sendMessage("Client message");
        now=millis();
      }
    }

    void webSocketEvent(String msg){
     println(msg);
     newEllipse=true;
    }

Error:

onError(IllegalArgumentException: hostname can't be null)
java.lang.IllegalArgumentException: hostname can't be null
    at java.net.InetSocketAddress.checkHost(InetSocketAddress.java:149)
    at java.net.InetSocketAddress.<init>(InetSocketAddress.java:216)
    at org.eclipse.jetty.websocket.client.io.ConnectionManager.toSocketAddress(ConnectionManager.java:130)
    at org.eclipse.jetty.websocket.client.io.ConnectionManager$PhysicalConnect.run(ConnectionManager.java:68)
    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)
Tagged:

Answers

  • You forgot about "//" in wsc= new WebsocketClient(this, "ws://1--.1--.5.222:9000");

Sign In or Register to comment.