MCPcopy Create free account
hub / github.com/python-websockets/websockets / close_connection

Method close_connection

tests/legacy/test_protocol.py:173–189  ·  view source on GitHub ↗

Execute a closing handshake. This puts the connection in the CLOSED state.

(self, code=CloseCode.NORMAL_CLOSURE, reason="close")

Source from the content-addressed store, hash-verified

171 self.receive_eof()
172
173 def close_connection(self, code=CloseCode.NORMAL_CLOSURE, reason="close"):
174 """
175 Execute a closing handshake.
176
177 This puts the connection in the CLOSED state.
178
179 """
180 close_frame_data = Close(code, reason).serialize()
181 # Prepare the response to the closing handshake from the remote side.
182 self.receive_frame(Frame(True, OP_CLOSE, close_frame_data))
183 self.receive_eof_if_client()
184 # Trigger the closing handshake from the local side and complete it.
185 self.loop.run_until_complete(self.protocol.close(code, reason))
186 # Empty the outgoing data stream so we can make assertions later on.
187 self.assertOneFrameSent(True, OP_CLOSE, close_frame_data)
188
189 assert self.protocol.state is State.CLOSED
190
191 def half_close_connection_local(
192 self,

Calls 7

receive_frameMethod · 0.95
receive_eof_if_clientMethod · 0.95
assertOneFrameSentMethod · 0.95
CloseClass · 0.90
FrameClass · 0.90
serializeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected