muthesius.net
Class WebSocketP5

java.lang.Object
  extended by muthesius.net.WebSocketP5

public class WebSocketP5
extends java.lang.Object

+Example
/*
	Simple WebSocketServer Example
	http://github.com/muthesius/WebSocketP5
 */

import muthesius.net.*;
import org.webbitserver.*;

WebSocketP5 socket;

void setup() {
  socket = new WebSocketP5(this,8080);
}

void draw() {}

void stop(){
	socket.stop();
}

void mousePressed(){
  socket.broadcast("hello from processing!");
}

void websocketOnMessage(WebSocketConnection con, String msg){
	println(msg);
}

void websocketOnOpen(WebSocketConnection con){
  println("A client joined");
}

void websocketOnClosed(WebSocketConnection con){
  println("A client left");
}

Field Summary
static java.lang.String DEFAULT_SOCKET
           
static java.lang.String VERSION
           
 
Constructor Summary
WebSocketP5(processing.core.PApplet theParent)
          Initialize a Websocket as a Webbit Webserver with a socket.
WebSocketP5(processing.core.PApplet theParent, int port)
           
WebSocketP5(processing.core.PApplet theParent, int port, java.lang.String socketname)
           
 
Method Summary
 void broadcast(java.lang.String msg)
          Broadcast a message to all clients
 void dispose()
           
 int getPort()
          Return the port of the server.
 java.lang.String getUri()
          Return the URI of the server.
 int howManyConnections()
          How many connections do we have?
 void onClose(WebSocketConnection conn)
           
 void onMessage(WebSocketConnection connection, byte[] message)
           
 void onMessage(WebSocketConnection conn, java.lang.String message)
           
 void onOpen(WebSocketConnection conn)
           
 void onPong(WebSocketConnection connection, java.lang.String message)
           
 void sendAll(java.lang.String msg)
          Alias for broadcast
 void start()
           
 void stop()
           
static java.lang.String version()
          Return the version of the library.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final java.lang.String VERSION
See Also:
Constant Field Values

DEFAULT_SOCKET

public static final java.lang.String DEFAULT_SOCKET
See Also:
Constant Field Values
Constructor Detail

WebSocketP5

public WebSocketP5(processing.core.PApplet theParent)
Initialize a Websocket as a Webbit Webserver with a socket.

Parameters:
theParent -
port - The port the socket should be served on (mus be >1024)
socketname - Give the socket a name - this results to the URL in your javascript, e.g. you give it "mysocket", the URL will be ws:///mysocket
+Example
/*
	Simple WebSocketServer Example
	http://github.com/muthesius/WebSocketP5
 */

import muthesius.net.*;
import org.webbitserver.*;

WebSocketP5 socket;

void setup() {
  socket = new WebSocketP5(this,8080);
}

void draw() {}

void stop(){
	socket.stop();
}

void mousePressed(){
  socket.broadcast("hello from processing!");
}

void websocketOnMessage(WebSocketConnection con, String msg){
	println(msg);
}

void websocketOnOpen(WebSocketConnection con){
  println("A client joined");
}

void websocketOnClosed(WebSocketConnection con){
  println("A client left");
}

WebSocketP5

public WebSocketP5(processing.core.PApplet theParent,
                   int port)

WebSocketP5

public WebSocketP5(processing.core.PApplet theParent,
                   int port,
                   java.lang.String socketname)
Method Detail

start

public void start()

stop

public void stop()

dispose

public void dispose()

version

public static java.lang.String version()
Return the version of the library.

Returns:
String

getPort

public int getPort()
Return the port of the server.

Returns:
int The port the server is running on

getUri

public java.lang.String getUri()
Return the URI of the server.

Returns:
String

howManyConnections

public int howManyConnections()
How many connections do we have?


broadcast

public void broadcast(java.lang.String msg)
Broadcast a message to all clients

Parameters:
msg - The message to braodcast to all connected clients

sendAll

public void sendAll(java.lang.String msg)
Alias for broadcast


onOpen

public void onOpen(WebSocketConnection conn)

onClose

public void onClose(WebSocketConnection conn)

onMessage

public void onMessage(WebSocketConnection conn,
                      java.lang.String message)

onMessage

public void onMessage(WebSocketConnection connection,
                      byte[] message)

onPong

public void onPong(WebSocketConnection connection,
                   java.lang.String message)


processing library websocketP5 by jens alexander ewald. (c) 2011