proposed patch to support sending websocket frames with given type

25 views
Skip to first unread message

M C

unread,
Nov 1, 2011, 11:33:03 AM11/1/11
to Gretty Web Framework
hi, would like to propose this very small patch to support sending
websocket frames of given type, which includes binary frames -- best,
M


diff --git a/gretty/src/org/mbte/gretty/httpserver/
GrettyWebSocketHandler.groovy b/gretty/src/org/mbte/gretty/httpserver/
GrettyWebSocketHandler.groovy
index 94effc0..3745432 100644
--- a/gretty/src/org/mbte/gretty/httpserver/
GrettyWebSocketHandler.groovy
+++ b/gretty/src/org/mbte/gretty/httpserver/
GrettyWebSocketHandler.groovy
@@ -27,6 +27,7 @@ import org.jboss.netty.channel.ChannelEvent
import org.jboss.netty.channel.MessageEvent
import org.jboss.netty.handler.codec.http.websocket.WebSocketFrame
import org.jboss.netty.channel.ChannelStateEvent
+import org.jboss.netty.buffer.ChannelBuffers

import
org.jboss.netty.handler.codec.http.websocket.DefaultWebSocketFrame
import org.jboss.netty.channel.ChannelState
@@ -55,20 +56,38 @@ import org.mbte.gretty.JacksonCategory
sendInternal(object)
}

+ protected void send(int type, Object object) {
+ sendInternal(type, object)
+ }
+
protected void sendJson(data) {
send(JacksonCategory.toJsonString(data))
}

+ protected void sendJson(int type, data) {
+ send(type, JacksonCategory.toJsonString(data))
+ }
+
protected void sendInternal(object) {
socket.channel.write(new
DefaultWebSocketFrame(object?.toString()))
}

+ protected void sendInternal(int type, object) {
+ socket.channel.write(new DefaultWebSocketFrame(type,
ChannelBuffers.wrappedBuffer(object?.toString()?.getBytes("UTF-8"))))
+ }
+
protected void broadcast(Object object) {
for(e in allConnected.entrySet()) {
e.value.sendInternal object
}
}

+ protected void broadcast(int type, Object object) {
+ for(e in allConnected.entrySet()) {
+ e.value.sendInternal type, object
+ }
+ }
+
protected void initConnection(ChannelHandlerContext ctx,
GrettyHttpResponse response) {
def channel = ctx.channel
if(!socket)
Reply all
Reply to author
Forward
0 new messages