Skip to content

Instantly share code, notes, and snippets.

@drewww
Created October 5, 2012 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drewww/3840017 to your computer and use it in GitHub Desktop.
Save drewww/3840017 to your computer and use it in GitHub Desktop.
SockJS 'close' event debugging
package com.multitudecorp.benchmark.client;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
// This library is available here: https://github.com/TooTallNate/Java-WebSocket
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
public class MinimalSockJSClient extends WebSocketClient {
public MinimalSockJSClient(URI serverURI) {
super(serverURI);
}
@Override
public void onClose(int arg0, String arg1, boolean arg2) {
System.out.println("closed!");
}
@Override
public void onError(Exception e) {
System.out.println("error! " + e);
}
@Override
public void onMessage(String message) {
System.out.println("message: " + message);
}
@Override
public void onOpen(ServerHandshake arg0) {
System.out.println("open");
}
public static void main(String[] args) {
try {
MinimalSockJSClient c = new MinimalSockJSClient(new URI("ws://localhost:8080/websocket"));
c.connect();
System.out.println("connect fired, waiting.");
Thread.sleep(6000);
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
var sockjs_lib = require('sockjs'),
http = require('http');
var httpServer = http.createServer();
var sockjs = sockjs_lib.createServer();
sockjs.installHandlers(httpServer);
httpServer.listen(8080);
sockjs.on("connection", function(socket) {
socket.on("close", function() {
console.log(socket.id + " has closed.");
});
console.log(socket.id + " has connected.");
setTimeout(function() {
socket.close();
}, 2000);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment