This commit is contained in:
meejah 2021-04-07 16:28:19 -06:00
parent 0bfff5242b
commit b095b6919a
2 changed files with 5 additions and 12 deletions

View File

@ -58,6 +58,7 @@ class TransitConnection(LineReceiver):
""" """
if self._buddy is not None: if self._buddy is not None:
log.msg("buddy_disconnected {}".format(self._buddy.get_token())) log.msg("buddy_disconnected {}".format(self._buddy.get_token()))
# XXX if our buddy is a WebSocket, this isn't the right way?
self._buddy._client.transport.loseConnection() self._buddy._client.transport.loseConnection()
self._buddy = None self._buddy = None
@ -237,7 +238,8 @@ class WebSocketTransitConnection(WebSocketServerProtocol):
""" """
if self._buddy is not None: if self._buddy is not None:
log.msg("buddy_disconnected {}".format(self._buddy.get_token())) log.msg("buddy_disconnected {}".format(self._buddy.get_token()))
self._buddy._client.transport.loseConnection() # XXX if our buddy is tcp this is wrong
self._buddy._client.disconnect()
self._buddy = None self._buddy = None
def connectionMade(self): def connectionMade(self):

View File

@ -36,11 +36,6 @@ class RelayEchoClient(WebSocketClientProtocol):
True, True,
) )
# def onConnecting(self, details):
# return types.ConnectingRequest(
# protocols=["binary"],
# )
def onMessage(self, data, isBinary): def onMessage(self, data, isBinary):
print(">onMessage: {} bytes".format(len(data))) print(">onMessage: {} bytes".format(len(data)))
print(data, isBinary) print(data, isBinary)
@ -48,7 +43,6 @@ class RelayEchoClient(WebSocketClientProtocol):
self.factory.ready.callback(None) self.factory.ready.callback(None)
else: else:
self._received += data self._received += data
# return False
def onClose(self, wasClean, code, reason): def onClose(self, wasClean, code, reason):
print(">onClose", wasClean, code, reason) print(">onClose", wasClean, code, reason)
@ -65,18 +59,15 @@ def main(reactor):
f = WebSocketClientFactory("ws://127.0.0.1:4002/") f = WebSocketClientFactory("ws://127.0.0.1:4002/")
f.reactor = reactor f.reactor = reactor
f.protocol = RelayEchoClient f.protocol = RelayEchoClient
## f.protocols = ["binary"]
# NB: write our own factory, probably..
f.token = "a" * 64 f.token = "a" * 64
f.side = "0" * 16 if will_send_message else "1" * 16 f.side = "0" * 16 if will_send_message else "1" * 16
f.done = Deferred() f.done = Deferred()
f.ready = Deferred() f.ready = Deferred()
proto = yield ep.connect(f) proto = yield ep.connect(f)
# proto_d = ep.connect(f)
# print("proto_d", proto_d)
# proto = yield proto_d
print("proto", proto) print("proto", proto)
yield f.ready yield f.ready
print("ready") print("ready")
if will_send_message: if will_send_message:
for _ in range(5): for _ in range(5):