| 3943 | |
| 3944 | # Adapter to turn websocket into a stream "connection" |
| 3945 | class BinWebSocket(object): |
| 3946 | def __init__(self, hostname, port): |
| 3947 | self.ws = websocket.WebSocket() |
| 3948 | self.ws.connect("ws://" + hostname + ":" + str(port)) |
| 3949 | self.recvbuf = bytes() |
| 3950 | |
| 3951 | def send(self, data): |
| 3952 | self.ws.send(data, websocket.ABNF.OPCODE_BINARY) |
| 3953 | |
| 3954 | def recv(self, maxlen): |
| 3955 | while len(self.recvbuf) < maxlen: |
| 3956 | self.recvbuf += self.ws.recv() |
| 3957 | |
| 3958 | ret = self.recvbuf[:maxlen] |
| 3959 | self.recvbuf = self.recvbuf[maxlen:] |
| 3960 | return ret |
| 3961 | |
| 3962 | ws = BinWebSocket('localhost', ws_port) |
| 3963 | lconn = wire.LightningConnection(ws, |
no outgoing calls