MCPcopy Index your code
hub / github.com/websocket-client/websocket-client / initialize_socket

Method initialize_socket

websocket/_app.py:387–440  ·  view source on GitHub ↗
(reconnecting: bool = False)

Source from the content-addressed store, hash-verified

385 self._callback(self.on_close, close_status_code, close_reason)
386
387 def initialize_socket(reconnecting: bool = False) -> None:
388 if reconnecting and self.sock:
389 self.sock.shutdown()
390
391 self.sock = WebSocket(
392 self.get_mask_key,
393 sockopt=sockopt,
394 sslopt=sslopt,
395 fire_cont_frame=self.on_cont_message is not None,
396 skip_utf8_validation=skip_utf8_validation,
397 enable_multithread=True,
398 dispatcher=dispatcher,
399 )
400
401 self.sock.settimeout(getdefaulttimeout())
402 try:
403 header = self.header() if callable(self.header) else self.header
404
405 self.sock.connect(
406 self.url,
407 header=header,
408 cookie=self.cookie,
409 http_proxy_host=http_proxy_host,
410 http_proxy_port=http_proxy_port,
411 http_no_proxy=http_no_proxy,
412 http_proxy_auth=http_proxy_auth,
413 http_proxy_timeout=http_proxy_timeout,
414 subprotocols=self.subprotocols,
415 host=host,
416 origin=origin,
417 suppress_origin=suppress_origin,
418 proxy_type=proxy_type,
419 socket=self.prepared_socket,
420 )
421
422 _logging.info("Websocket connected")
423
424 if self.ping_interval:
425 self._start_ping_thread()
426
427 if reconnecting and self.on_reconnect:
428 self._callback(self.on_reconnect)
429 else:
430 self._callback(self.on_open)
431
432 dispatcher.read(self.sock.sock, read, check)
433 except (
434 WebSocketConnectionClosedException,
435 ConnectionRefusedError,
436 KeyboardInterrupt,
437 SystemExit,
438 Exception,
439 ) as e:
440 handleDisconnect(e, reconnecting)
441
442 def read() -> bool:
443 if not self.keep_running:

Callers

nothing calls this directly

Calls 8

_start_ping_threadMethod · 0.95
_callbackMethod · 0.95
WebSocketClass · 0.85
getdefaulttimeoutFunction · 0.85
shutdownMethod · 0.80
settimeoutMethod · 0.80
connectMethod · 0.80
readMethod · 0.45

Tested by

no test coverage detected