class_docstr: Creates socket server that sends the received data to the DeepPavlov model and returns model response.
  
  The server receives bytes array consists of the `header` and the `body`. The `header` is the first 4 bytes
  of the array - `body` length in bytes represented by a packed unsigned int (byte order is little-endian).
  `body` is dictionary serialized to JSON formatted bytes array that server sends to the model. The dictionary
  keys should match model arguments names, the values should be lists or tuples of inferenced values.
  
  Socket server request creation example:
      >>> from deeppavlov.utils.socket import encode
      >>> request = encode({"context":["Elon Musk launched his cherry Tesla roadster to the Mars orbit"]})
      >>> request
      b'I{"x": ["Elon Musk launched his cherry Tesla roadster to the Mars orbit"]}'
  
  Socket server response, like the request, consists of the header and the body. Response body is dictionary
  {'status': status, 'payload': payload} serialized to a JSON formatted byte array, where:
      status (str): 'OK' if the model successfully processed the data, else - error message.
      payload: (Optional[List[Tuple]]): The model result if no error has occurred, otherwise None.
class_docstr_tok: ["Creates","socket","server","that","sends","the","received","data","to","the","DeepPavlov","model","and","returns","model","response",".","The","server","receives","bytes","array","consists","of","the","`","header","`","and","the","`","body","`",".","The","`","header","`","is","the","first","4","bytes","of","the","array","-","`","body","`","length","in","bytes","represented","by","a","packed","unsigned","int","(","byte","order","is","little-endian",")",".","`","body","`","is","dictionary","serialized","to","JSON","formatted","bytes","array","that","server","sends","to","the","model",".","The","dictionary","keys","should","match","model","arguments","names",",","the","values","should","be","lists","or","tuples","of","inferenced","values",".","Socket","server","request","creation","example",":",">",">",">","from","deeppavlov.utils.socket","import","encode",">",">",">","request","=","encode","(","{","``","context","''",":","[","``","Elon","Musk","launched","his","cherry","Tesla","roadster","to","the","Mars","orbit","''","]","}",")",">",">",">","request","b","'","I\u0000\u0000\u0000","{","``","x","''",":","[","``","Elon","Musk","launched","his","cherry","Tesla","roadster","to","the","Mars","orbit","''","]","}","'","Socket","server","response",",","like","the","request",",","consists","of","the","header","and","the","body",".","Response","body","is","dictionary","{","'status","'",":","status",",","'payload","'",":","payload","}","serialized","to","a","JSON","formatted","byte","array",",","where",":","status","(","str",")",":","'OK","'","if","the","model","successfully","processed","the","data",",","else","-","error","message",".","payload",":","(","Optional","[","List","[","Tuple","]","]",")",":","The","model","result","if","no","error","has","occurred",",","otherwise","None","."]
docstr: Initializes socket server.
  
  Args:
      model_config: Path to the config file.
      socket_type: Socket family. "TCP" for the AF_INET socket server, "UNIX" for UNIX Domain Socket server.
      port: Port number for the AF_INET address family. If parameter is not defined, the port number from the
          utils/settings/server_config.json is used.
      socket_file: Path to the file to which UNIX Domain Socket server connects. If parameter is not defined,
          the path from the utils/settings/server_config.json is used.
  
  Raises:
      ValueError: If ``socket_type`` parameter is neither "TCP" nor "UNIX".
docstr_tok: ["Initializes","socket","server",".","Args",":","model_config",":","Path","to","the","config","file",".","socket_type",":","Socket","family",".","``","TCP","''","for","the","AF_INET","socket","server",",","``","UNIX","''","for","UNIX","Domain","Socket","server",".","port",":","Port","number","for","the","AF_INET","address","family",".","If","parameter","is","not","defined",",","the","port","number","from","the","utils\/settings\/server_config.json","is","used",".","socket_file",":","Path","to","the","file","to","which","UNIX","Domain","Socket","server","connects",".","If","parameter","is","not","defined",",","the","path","from","the","utils\/settings\/server_config.json","is","used",".","Raises",":","ValueError",":","If","``","socket_type","``","parameter","is","neither","``","TCP","''","nor","``","UNIX","''","."]
code: def __init__(
      self,
      model_config: Path,
      socket_type: str,
      port: Optional[int] = None,
      socket_file: Optional[Union[str, Path]] = None,
  ) -> None:
      """Initializes socket server.
  
      Args:
          model_config: Path to the config file.
          socket_type: Socket family. "TCP" for the AF_INET socket server, "UNIX" for UNIX Domain Socket server.
          port: Port number for the AF_INET address family. If parameter is not defined, the port number from the
              utils/settings/server_config.json is used.
          socket_file: Path to the file to which UNIX Domain Socket server connects. If parameter is not defined,
              the path from the utils/settings/server_config.json is used.
  
      Raises:
          ValueError: If ``socket_type`` parameter is neither "TCP" nor "UNIX".
  
      """
      server_params = get_server_params(model_config)
      socket_type = socket_type or server_params["socket_type"]
      self._loop = asyncio.get_event_loop()
  
      if socket_type == "TCP":
          host = server_params["host"]
          port = port or server_params["port"]
          self._launch_msg = f'{server_params["socket_launch_message"]} http://{host}:{port}'
          self._loop.create_task(
              asyncio.start_server(self._handle_client, host, port)
          )
      elif socket_type == "UNIX":
          socket_file = socket_file or server_params["unix_socket_file"]
          socket_path = Path(socket_file).resolve()
          if socket_path.exists():
              socket_path.unlink()
          self._launch_msg = (
              f'{server_params["socket_launch_message"]} {socket_file}'
          )
          self._loop.create_task(
              asyncio.start_unix_server(
                  self._handle_client, socket_file
              )
          )
      else:
          raise ValueError(
              f'socket type "{socket_type}" is not supported'
          )
  
      self._model = build_model(model_config)
      self._model_args_names = server_params["model_args_names"]
  
file_path: DeepPavlov/deeppavlov/utils/socket/socket.py
imports: import asyncio
  import json
  from logging import getLogger
  from pathlib import Path
  from struct import pack, unpack
  from typing import Any, List, Optional, Tuple, Union
  from deeppavlov.core.commands.infer import build_model
  from deeppavlov.core.common.chainer import Chainer
  from deeppavlov.core.data.utils import jsonify_data
  from deeppavlov.utils.connector import DialogLogger
  from deeppavlov.utils.server import get_server_params
label_desc: Use image node_id 1 to create a new SocketServer object  with example: obj = SocketServer(model_config, socket_type, port, socket_file)