My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Featured
Downloads
Links

Java WebSocket Client

Weberknecht is a Java implementation of the client side of the IETF WebSocket Protocol Draft draft-ietf-hybi-thewebsocketprotocol-00 (May 23, 2010) for use in Java SE or Android applications.

Tested with the following WebSocket servers:

Usage

This short code snippet shows how to integrate weberknecht in your application:

try {
	URI url = new URI("ws://127.0.0.1:8080/test");
	WebSocket websocket = new WebSocketConnection(url);
	
	// Register Event Handlers
	websocket.setEventHandler(new WebSocketEventHandler() {
		public void onOpen()
		{
			System.out.println("--open");
		}
				
		public void onMessage(WebSocketMessage message)
		{
			System.out.println("--received message: " + message.getText());
		}
				
		public void onClose()
		{
			System.out.println("--close");
		}
	});
	
	// Establish WebSocket Connection
	websocket.connect();
	
	// Send UTF-8 Text
	websocket.send("hello world");
	
	// Close WebSocket Connection
	websocket.close();
}
catch (WebSocketException wse) {
	wse.printStackTrace();
}
catch (URISyntaxException use) {
	use.printStackTrace();
}
Powered by Google Project Hosting