Skip to content

Instantly share code, notes, and snippets.

@cheriimoya
Created June 4, 2017 17:30
Show Gist options
  • Save cheriimoya/8a81d32b2eef6b38ef369cf56600e120 to your computer and use it in GitHub Desktop.
Save cheriimoya/8a81d32b2eef6b38ef369cf56600e120 to your computer and use it in GitHub Desktop.
import websockets.*;
WebsocketServer ws;
ArrayList<String> nachrichten;
boolean newMessages = false;
void setup(){
nachrichten = new ArrayList<String>();
ws = new WebsocketServer(this, 9000, "/chat");
}
void draw(){
if(newMessages){
println(nachrichten.get(nachrichten.size()-1));
ws.sendMessage(nachrichten.get(nachrichten.size()-1));
newMessages = false;
}
}
//void mousePressed(){
// newMessages = true;
// nachrichten.add("lala");
//}
void webSocketServerEvent(String msg){
nachrichten.add(msg);
newMessages = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment