# eric7.RemoteServer.EricServer

Module implementing the eric remote server.

### Global Attributes

None

### Classes

EricServer | Class implementing the eric remote server.

### Functions

None

## EricServer

Class implementing the eric remote server.

### Derived from

None

### Class Attributes

None

### Class Methods

None

### Methods

EricServer | Constructor
__acceptIdeConnection | Private method to accept the connection on the listening IDE server socket.
__closeIdeConnection | Private method to close the connection to an eric-ide.
__handleEchoRequest | Private method to handle an 'Echo' request.
__handleRequest | Private method handling or dispatching the received requests.
__handleServerRequest | Private method to handle a 'Server' request.
__initializeIdeSocket | Private method to initialize and register the eric-ide server socket.
__receiveBytes | Private method to receive the given length of bytes.
__receiveJson | Private method to receive a JSON encoded command and data from the server.
__registerInternalHandlers | Private method to register request handler categories of this class.
__serviceIdeConnection | Private method to service the eric-ide connection.
__shutdown | Private method to shut down the server.
__unregisterIdeSocket | Private method to unregister the eric-ide server socket because only one connection is allowed.
getSelector | Public method to get a reference to the selector object.
isSocketClosed | Public method to check, if a given socket is closed.
receiveJsonCommand | Public method to receive a JSON encoded command and data.
registerRequestHandler | Public method to register a request handler method for the given request category.
run | Public method implementing the remote server main loop.
sendJson | Public method to send a single refactoring command to the server.
sendJsonCommand | Public method to send a JSON encoded command/response via a given socket.
unregisterRequestHandler | Public method to unregister a handler for the given request category.

### Static Methods

None

#### EricServer (Constructor)

EricServer(port=42024, useIPv6=False)

Constructor

port (int (optional))
  port to listen on (defaults to 42024)
useIPv6 (bool (optional))
  flag indicating to use IPv6 protocol (defaults to False)

#### EricServer.__acceptIdeConnection

__acceptIdeConnection(sock)

Private method to accept the connection on the listening IDE server socket.

sock (socket.socket)
  reference to the listening socket

#### EricServer.__closeIdeConnection

__closeIdeConnection(shutdown=False)

Private method to close the connection to an eric-ide.

shutdown (bool)
  flag indicating a shutdown process

#### EricServer.__handleEchoRequest

__handleEchoRequest(request, params, reqestUuid)

Private method to handle an 'Echo' request.

request (str)
  request name
params (dict)
  request parameters
reqestUuid (str)
  UUID of the associated request as sent by the eric IDE (defaults to "", i.e. no UUID received)

#### EricServer.__handleRequest

__handleRequest(category, request, params, reqestUuid)

Private method handling or dispatching the received requests.

category (EricRequestCategory)
  category of the request
request (str)
  request name
params (dict)
  request parameters
reqestUuid (str)
  UUID of the associated request as sent by the eric IDE

#### EricServer.__handleServerRequest

__handleServerRequest(request, params, reqestUuid)

Private method to handle a 'Server' request.

request (str)
  request name
params (dict)
  request parameters
reqestUuid (str)
  UUID of the associated request as sent by the eric IDE (defaults to "", i.e. no UUID received)

#### EricServer.__initializeIdeSocket

__initializeIdeSocket()

Private method to initialize and register the eric-ide server socket.

#### EricServer.__receiveBytes

__receiveBytes(length, sock)

Private method to receive the given length of bytes.

length (int)
  bytes to receive
sock (socket.socket)
  reference to the socket to receive the data from

Return:
  received bytes or None if connection closed

Return Type:
  bytes

#### EricServer.__receiveJson

__receiveJson()

Private method to receive a JSON encoded command and data from the server.

Return:
  tuple containing the received service category, the command, a dictionary containing the associated data and the UUID of the request

Return Type:
  tuple of (int, str, dict, str)

#### EricServer.__registerInternalHandlers

__registerInternalHandlers()

Private method to register request handler categories of this class.

#### EricServer.__serviceIdeConnection

__serviceIdeConnection(key)

Private method to service the eric-ide connection.

key (selectors.SelectorKey)
  reference to the SelectorKey object associated with the connection to be serviced

#### EricServer.__shutdown

__shutdown()

Private method to shut down the server.

#### EricServer.__unregisterIdeSocket

__unregisterIdeSocket()

Private method to unregister the eric-ide server socket because only one connection is allowed.

#### EricServer.getSelector

getSelector()

Public method to get a reference to the selector object.

Return:
  reference to the selector object

Return Type:
  selectors.BaseSelector

#### EricServer.isSocketClosed

isSocketClosed(sock)

Public method to check, if a given socket is closed.

sock (socket.socket)
  reference to the socket to be checked

Return:
  flag indicating a closed state

Return Type:
  bool

#### EricServer.receiveJsonCommand

receiveJsonCommand(sock)

Public method to receive a JSON encoded command and data.

sock (socket.socket)
  reference to the socket to receive the data from

Return:
  dictionary containing the JSON command data or None to signal an issue while receiving data

Return Type:
  dict

#### EricServer.registerRequestHandler

registerRequestHandler(requestCategory, handler)

Public method to register a request handler method for the given request category.

requestCategory (EricRequestCategory or int (>= EricRequestCategory.UserCategory))
  request category to be registered
handler (function(request:str, params:dict, requestUuid:str))
  reference to the handler method. This handler must accept the parameters 'request', 'params', and 'requestUuid'

Raises ValueError:
  raised to signal a request category collision

#### EricServer.run

run()

Public method implementing the remote server main loop.

Exiting the inner loop, that receives and dispatches the requests, will cause the server to stop and exit. The main loop handles these requests.

- exit - exit the handler loop and wait for the next connection
- shutdown - exit the handler loop and perform a clean shutdown

Return:
  flag indicating a clean shutdown

Return Type:
  bool

#### EricServer.sendJson

sendJson(category, reply, params, reqestUuid="")

Public method to send a single refactoring command to the server.

category (EricRequestCategory)
  service category
reply (str)
  reply name to be sent
params (dict)
  dictionary of named parameters for the request
reqestUuid (str)
  UUID of the associated request as sent by the eric IDE (defaults to "", i.e. no UUID received)

#### EricServer.sendJsonCommand

sendJsonCommand(jsonCommand, sock)

Public method to send a JSON encoded command/response via a given socket.

jsonCommand (dict or str)
  dictionary containing the command data or a JSON encoded command string
sock (socket.socket)
  reference to the socket to send the data to

Return:
  flag indicating a successful transmission

Return Type:
  bool

#### EricServer.unregisterRequestHandler

unregisterRequestHandler(requestCategory, ignoreError=False)

Public method to unregister a handler for the given request category.

Note: This method will raise a KeyError exception in case the request category has not been registered and ignoreError is False (the default).

requestCategory (EricRequestCategory or int (>= EricRequestCategory.UserCategory))
  request category to be unregistered
ignoreError (bool (optional))
  flag indicating to ignore errors (defaults to False)

Up