| 3992 | |
| 3993 | # Adapter to turn websocket into a stream "connection" |
| 3994 | class BinWebSocket(object): |
| 3995 | def __init__(self, hostname, port): |
| 3996 | self.ws = websocket.WebSocket() |
| 3997 | self.ws.connect("ws://" + hostname + ":" + str(port)) |
| 3998 | self.recvbuf = bytes() |
| 3999 | |
| 4000 | def send(self, data): |
| 4001 | self.ws.send(data, websocket.ABNF.OPCODE_BINARY) |
| 4002 | |
| 4003 | def recv(self, maxlen): |
| 4004 | while len(self.recvbuf) < maxlen: |
| 4005 | self.recvbuf += self.ws.recv() |
| 4006 | |
| 4007 | ret = self.recvbuf[:maxlen] |
| 4008 | self.recvbuf = self.recvbuf[maxlen:] |
| 4009 | return ret |
| 4010 | |
| 4011 | ws = BinWebSocket('localhost', ws_port) |
| 4012 | lconn = wire.LightningConnection(ws, |
no outgoing calls