File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -375,8 +375,11 @@ async def matlab_view(req):
375375
376376 # WebSocket
377377 if (
378- reqH .get ("connection" ) == "Upgrade"
379- and reqH .get ("upgrade" ) == "websocket"
378+ reqH .get ("connection" )
379+ # Fixes issue #9 on github.
380+ and reqH .get ("connection" ).lower () == "upgrade"
381+ and reqH .get ("upgrade" )
382+ and reqH .get ("upgrade" ).lower () == "websocket"
380383 and req .method == "GET"
381384 ):
382385 ws_server = web .WebSocketResponse ()
@@ -394,6 +397,19 @@ async def wsforward(ws_from, ws_to):
394397 async for msg in ws_from :
395398 mt = msg .type
396399 md = msg .data
400+
401+ # When a websocket is closed by the MATLAB JSD, it sends out a few http requests to the Embedded Connector about the events
402+ # that had occured (figureWindowClosed etc.)
403+ # The Embedded Connector responds by sending a message of type 'Error' with close code as Abnormal closure.
404+ # When this happens, matlab-proxy can safely exit out of the loop
405+ # and close the websocket connection it has with the Embedded Connector (ws_client)
406+ if (
407+ mt == aiohttp .WSMsgType .ERROR
408+ and ws_from .close_code
409+ == aiohttp .WSCloseCode .ABNORMAL_CLOSURE
410+ ):
411+ break
412+
397413 if mt == aiohttp .WSMsgType .TEXT :
398414 await ws_to .send_str (md )
399415 elif mt == aiohttp .WSMsgType .BINARY :
You can’t perform that action at this time.
0 commit comments