     @socket = null
     
     # Holds buffered data
-    @buffer = new ByteBuffer(0)
+    @buffer = new ByteBuffer()
     
     # Holds (partial) packet (if any) and its remaining size in bytes
     @packet = null

  send: (packet) ->
    if @connected
      
      console.log 'sending packet', packet
      
      packet.finalize()
      
      packet.dump()
      
      @socket.send(packet.buffer)
      

        @on.disconnect.dispatch(@, e)
      
      @socket.onmessage = (e) =>
        @buffer.clip()
        @buffer.append(e.data.byteLength).write(e.data)
        @buffer.front()
        @on.dataReceive.dispatch(@)
      
      @socket.onerror = (e) ->
