mashupbots / socko

A Scala web server powered by Netty networking and AKKA processing.
Other
255 stars 51 forks source link

event.readBinary() causes UnsupportedOperationException #81

Closed chiappone closed 10 years ago

chiappone commented 10 years ago

I am working with a websocket client that sends binary data. When trying to read the event from the websocketFrame I get the following exception:

2014-01-23 19:32:25,520 [MessageBroker-akka.actor.default-dispatcher-55] ERROR akka.actor.OneForOneStrategy - direct buffer
java.lang.UnsupportedOperationException: direct buffer
    at io.netty.buffer.UnpooledUnsafeDirectByteBuf.array(UnpooledUnsafeDirectByteBuf.java:199) ~[netty-all-4.0.14.Final.jar:4.0.14.Final]
    at org.mashupbots.socko.events.WebSocketFrameEvent.readBinary(WebSocketFrameEvent.scala:95) ~[socko-webserver_2.10-0.4.1.jar:0.4.1]

Do you have any ideas on a work around for this.

Thanks!

veebs commented 10 years ago

Thanks for reporting this. It's fixed the next release. In the interim, you can try this work around

  val data = if (event.wsFrame.content.readableBytes > 0) {
      val a = new Array[Byte](event.wsFrame.content.readableBytes)
      event.wsFrame.content.readBytes(a)
      a
    } else Array.empty[Byte]

event is the WebSocketFrameEvent when the binary data is received.

Thanks