Created
October 5, 2012 14:16
-
-
Save drewww/3840017 to your computer and use it in GitHub Desktop.
SockJS 'close' event debugging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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