Esempio n. 1
0
class WV_ViewServer(object):
    def __init__(self, handler, fname=None):
        self.wv = WV_Wrapper()
        self.buf = self.wv.get_bufflen()*'\0'
        self.handler = handler  # need this to send the msgs
        self.geometry_file = fname

    def send_binary_data(self, wsi, buf, ibuf):
        try:
            #dat = msgpack.packb(buf, encoding=None)
            #self.handler.write_message(dat, binary=True)
            self.handler.write_message(buf, binary=True)
        except Exception as err:
            ERROR("Exception in send_binary_data:", err)
            return -1
        return 0

    def send_geometry(self, first=False):
        self.wv.prepare_for_sends()

        if first:
            self.wv.send_GPrim(self, self.buf,  1, self.send_binary_data)  # send init packet
            self.wv.send_GPrim(self, self.buf, -1, self.send_binary_data)  # send initial suite of GPrims
        else:  #FIXME: add updating of GPRims here...
            pass

        self.wv.finish_sends()

    def on_message(self, message):
        DEBUG("binary ws got message: %s" % [ord(c) for c in message])

    def on_close(self):
        DEBUG("binary WebSocket closed")

    def open(self):
        DEBUG("binary WebSocket opened. addr=%d" % id(self))
        DEBUG("fname = %s" % self.geometry_file)
        try:
            self.create_geom()
            self.send_geometry(first=True)
        except Exception as err:
            ERROR('Exception: %s' % traceback.format_exc())
Esempio n. 2
0
def send_binary_data(wsi, buf, ibuf):
    print "In send_binary_data"
    print "length", len(buf)
    print "buffer", [buf[i] for i in range(0, ibuf)]
    print ibuf
    wsi.check()
    
    return 0

class wsi_server(object):
    
    def check(self):
        print "Hello from the Server"
        
    def write_to_file(self, name, buf):
        ''' Writes the binary data to a file
        '''
        
        with open(name, 'wb') as out:
            out.write(buf)

buf = 3205696*' '
wsi = wsi_server()
myWV.prepare_for_sends()
#myWV.send_GPrim(wsi, buf, 1, send_binary_data)
#myWV.send_GPrim(wsi, buf, 0, send_binary_data)
myWV.send_GPrim(wsi, buf, -1, send_binary_data)
myWV.finish_sends()
myWV.remove_GPrim(0)