Created
May 10, 2012 12:52
-
-
Save pledbrook/2652835 to your computer and use it in GitHub Desktop.
Embed Vert.x in Grails
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
import org.vertx.groovy.core.Vertx | |
class BootStrap { | |
def init = { servletContext -> | |
def vertx = Vertx.newVertx() | |
def httpServer = vertx.createHttpServer() | |
vertx.createSockJSServer(httpServer).installApp(prefix: '/events') { sock -> | |
sock.dataHandler { buff -> | |
sock << buff | |
} | |
} | |
httpServer.listen(8585) | |
} | |
def destroy = { | |
} | |
} |
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
<!doctype html> | |
<html> | |
<head> | |
<title>SockJS Test</title> | |
<script src="http://cdn.sockjs.org/sockjs-0.2.1.min.js"></script> | |
</head> | |
<body> | |
<script> | |
var sock = new SockJS('http://localhost:8585/events'); | |
sock.onopen = function() { | |
console.log('open'); | |
}; | |
sock.onmessage = function(e) { | |
console.log('message', e.data); | |
alert('received message echoed from server: ' + e.data); | |
}; | |
sock.onclose = function() { | |
console.log('close'); | |
}; | |
function send(message) { | |
if (sock.readyState == WebSocket.OPEN) { | |
console.log("sending message") | |
sock.send(message); | |
} else { | |
console.log("The socket is not open."); | |
} | |
} | |
</script> | |
<form onsubmit="return false;"> | |
<input type="text" name="message" value="Hello, World!"/> | |
<input type="button" value="Send SockJS data" onclick="send(this.form.message.value)"/> | |
</form> | |
</body> | |
</html> |
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
lib/vert.x-core.jar | |
lib/vert.x-platform.jar | |
lib/netty.jar | |
lib/jackson-core.jar | |
lib/jackson-mapper.jar |
Will this work without violationg cross domain policy? http://grails.1312388.n4.nabble.com/TCP-Socket-Server-td2285321.html
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Will this work without violationg cross domain policy? http://grails.1312388.n4.nabble.com/TCP-Socket-Server-td2285321.html