{"id":33137715,"url":"https://github.com/alexandrainst/processing_websockets","last_synced_at":"2026-02-12T11:31:27.118Z","repository":{"id":53775798,"uuid":"48043232","full_name":"alexandrainst/processing_websockets","owner":"alexandrainst","description":"A web socket library, including both server and client, for Processing","archived":false,"fork":false,"pushed_at":"2022-09-09T13:08:51.000Z","size":2000,"stargazers_count":88,"open_issues_count":14,"forks_count":33,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-05-14T03:09:06.549Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexandrainst.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-15T13:02:35.000Z","updated_at":"2024-02-16T15:03:42.000Z","dependencies_parsed_at":"2022-08-25T11:11:10.654Z","dependency_job_id":null,"html_url":"https://github.com/alexandrainst/processing_websockets","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/alexandrainst/processing_websockets","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexandrainst%2Fprocessing_websockets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexandrainst%2Fprocessing_websockets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexandrainst%2Fprocessing_websockets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexandrainst%2Fprocessing_websockets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexandrainst","download_url":"https://codeload.github.com/alexandrainst/processing_websockets/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexandrainst%2Fprocessing_websockets/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29364223,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-12T08:51:36.827Z","status":"ssl_error","status_checked_at":"2026-02-12T08:51:26.849Z","response_time":55,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-11-15T11:00:44.130Z","updated_at":"2026-02-12T11:31:27.112Z","avatar_url":"https://github.com/alexandrainst.png","language":"HTML","funding_links":[],"categories":["Libraries"],"sub_categories":["Contributions"],"readme":"# Websockets for Processing\n\n**Create websocket servers and clients, which makes it possible to communicate with the\noutside world including web sites. With this library it is possible to have true two-way\nreal-time connections with other Processing sketches, web sites, Internet of Things\ndevices, etc.**\n\n\u003e 🙋 We are looking for a new maintainer / owner of this repository\n\n## Download\nThe library can be downloaded here:\nhttps://github.com/alexandrainst/processing_websockets/blob/master/webSockets.zip?raw=true\n\n## Installation\nUnzip and put the extracted webSockets folder into the libraries folder of your Processing\nsketches. Reference and examples are included in the webSockets folder.\n\n## Examples explained\nI have provided two simple examples on using both the client and server part. These can be\nfound in the examples folder. Below I will go through each example, and elaborate their usage.\n\n### Websocket client\n\nIn the following I provide the full example code of creating a websocket client in Processing.\nIn the below code I draw a new ellipse at a random location (without removing the previous)\neach time I get a message from the websocket server, and I send a message to the server every\n5 seconds (\"Client message\").\n\n```java\nimport websockets.*;\n\nWebsocketClient wsc;\nint now;\nboolean newEllipse;\n\nvoid setup(){\n  size(200,200);\n  \n  newEllipse=true;\n  \n  //Here I initiate the websocket connection by connecting to \"ws://localhost:8025/john\", which is the uri of the server.\n  //this refers to the Processing sketch it self (you should always write \"this\").\n  wsc= new WebsocketClient(this, \"ws://localhost:8025/john\");\n  now=millis();\n}\n\nvoid draw(){\n    //Here I draw a new ellipse if newEllipse is true\n  if(newEllipse){\n    ellipse(random(width),random(height),10,10);\n    newEllipse=false;\n  }\n    \n    //Every 5 seconds I send a message to the server through the sendMessage method\n  if(millis()\u003enow+5000){\n    wsc.sendMessage(\"Client message\");\n    now=millis();\n  }\n}\n\n//This is an event like onMouseClicked. If you chose to use it, it will be executed whenever the server sends a message \nvoid webSocketEvent(String msg){\n println(msg);\n newEllipse=true;\n}\n```\n\n### Websocket server\n\nIn the following I provide the full example code of creating a websocket server in Processing.\nIn the below code I move an ellipse to a random location when I get a message from a client,\nand I send a message to ll clients every 5 seconds (\"Server message\").\n\n```java\nimport websockets.*;\n\nWebsocketServer ws;\nint now;\nfloat x,y;\n\nvoid setup(){\n  size(200,200);\n  \n  //Initiates the websocket server, and listens for incoming connections on ws://localhost:8025/john\n  ws= new WebsocketServer(this,8025,\"/john\");\n  now=millis();\n  x=0;\n  y=0;\n}\n\nvoid draw(){\n  background(0);\n  ellipse(x,y,10,10);\n  \n  //Send message to all clients very 5 seconds\n  if(millis()\u003enow+5000){\n    ws.sendMessage(\"Server message\");\n    now=millis();\n  }\n}\n\n//This is an event like onMouseClicked. If you chose to use it, it will be executed whenever a client sends a message\nvoid webSocketServerEvent(String msg){\n println(msg);\n x=random(width);\n y=random(height);\n}\n```\n\n### How to set custom headers on your client\n\nConstruct your `WebsocketClient` with custom headers passing them as a `StringArray`, with `key:value` pairs separated by colons:\n\n```java\n  StringList headers = new StringList();\n  headers.append(\"User-Agent:Processing\");\n  wsc=new WebsocketClient(this, \"ws://simple-websocket-server-echo.glitch.me/\", headers);\n```\n\n\n### Set message max size\n\nCall this method before calling the constructor to specify the message max size in bytes\n\n    WebsocketServer.setMaxMessageSize(200000);\n\n### Enable logging\n\nBy default logging has been disabled, as it looks like errors in the\nProcessing IDE's console. Call this method before calling the constructor\n\n    WebsocketServer.enableDebug();\n\n### How to be notified of user connections / disconnections\n\nImplement the following two methods, which will receive the user id hash and\nthe user IP address.\n\n```java\npublic void webSocketConnectEvent(String uid, String ip) {\n  println(\"Someone connected\", uid, ip);\n}\n  \npublic void webSocketDisconnectEvent(String uid, String ip) {\n  println(\"Someone disconnected\", uid, ip);\n}\n```\n\n### How to send a message to a specific user\n\nYou need the user ID to send a message to that user only. \nYou receive that user ID when the user first connects.\n\n    ws.sendMessageTo(\"message\", \"userID\");\n\nor\n\n    ws.sendMessageTo(byteArray, \"userID\");\n\n### How to instantiate the WebsocketServer in your own class instead of the PApplet\n\nNote the extra second argument in the constructor. That's the Object that will implement all the webSocketXXX() methods. Without that second argument it is assumed that the PApplet will implement such methods.\n\n```java\npublic class CaptainSocket {\n  WebsocketServer ws;\n  CaptainSocket(PApplet p5) {\n    ws = new WebsocketServer(p5, this, 8025, \"/miau\");\n  }\n  public void webSocketServerEvent(String msg) {\n    println(msg);\n  }\n}  \n\n... in your PApplet ...\n\nCaptainSocket  socket;\nvoid setup() {\n  socket = new CaptainSocket(this);\n}\n\n```\n\n## Technical development details\n\nThe library has been developed on a Mac with El Capitan, I have used the Eclipse Luna IDE,\nand I have only tested on Processing version 3.0.1.\n\nThe library is build with the Jetty websocket implementation, and different Jetty libraries\nare therefore needed for running this library. All dependencies are included in the downloadable\nzip file. The source code is available through this Github project (open source under MIT\nlicense) as well as included in the zip file below.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexandrainst%2Fprocessing_websockets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexandrainst%2Fprocessing_websockets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexandrainst%2Fprocessing_websockets/lists"}