Skip to content

Latest commit

 

History

History
53 lines (34 loc) · 2.07 KB

README.md

File metadata and controls

53 lines (34 loc) · 2.07 KB

#Websockets

Websocket IO package in Java. Written for implementation in CFML.

websocket-client

Simple Extension of websocket client by Too Tall Nate https://github.com/TooTallNate/Java-WebSocket

What it is

This project grew out of my need to implement a Websocket client in Lucee CFML Server (www.lucee.org). It implements a very basic Websocket client in Java. This client is callable as a Java object in CFML from within Lucee.

Installation

  1. Download the zip file or "git clone" the repo from the links on the project homepage.

  2. Build the project using Java, or just grab the com.bonnydoonmedia.io.jar file from the project root.

  3. Put the jar (or .class if you want to deploy just WSClient.class ) file in your Web project.

For an example of how and why you would implement the websocket client in a CFML app, see the Coldboxing app (https://github.com/robertdmunn/coldboxing). The client is called in /model/logging/WebSocketAppender.cfc.

Implementation

Load the Java class via Javaloader. You need java_websocket.jar (contained in the /lib folder in this project).

var paths = arraynew(1);
paths[1]= expandpath("/includes/java/java_websocket.jar");
paths[2]= expandpath("/includes/java/com.bonnydoonmedia.io.jar");
var uri = createObject( "java", "java.net.URI" ).init( "ws://" & getProperty("host") & ":" & getProperty("port") );
javaloader = createObject('component',"javaloader.JavaLoader").init(paths);
ws = javaloader.create( "com.bonnydoonmedia.io.WSClient" ).init( uri );

try{
    ws.connect();
}
catch(Any e){
    throw(message="Error opening socket to #getProperty("host")#:#getProperty("port")#",
    detail=e.message & e.detail & e.stacktrace,
    type="ConnectionException");
}

entry = "Some message.";

ws.send( entry );

ws.close();