UDPService¶
-
class
services.
UDPService
(_server, _params, _type=<SocketKind.SOCK_DGRAM: 2>, _family=<AddressFamily.AF_UNSPEC: 0>)¶ Bases:
services.SocketService
UDPService waits for incomming socket data and processes them
Parameters: {SocketService} -- Base class (SocketService) – Methods Summary
add_accept_handler
(sock, callback)Accept Handler for UDP Socket add_sockets
(sockets)Adds speficic sockets to the server bind
(port[, address, family])Bind a specific socket (here UDP) to the server bind_unix_socket
(file, mode)Special binding for UnixSockets - the way unix-sockets are reused depends extremly on OS Platform can_send
()Basic info wether service can send back or not close
()Basic close service get_service
(_params[, _server])Gets a service from service params EXAMPLE: _params[‘active_service’].append({ # tcp service “id”: 2, “antano_server_id”: 1, # needs to be the same as id above “service_type_id”: 2, “port”: 18002, “host”: “0.0.0.0”, “endpoint”: “”, # in case of rest or websocket /my_endpoint put “my_endpoint” “message_format_in_id”: 1, # message_format “message_format_out_id”: 1, # message_format }) on_received_message
(message, address, …)On received message will process the message and if there is a repsonse it will send back to the same stream the client has send run_processes
(_services, _num_of_process)Finally runs all processes for given sockets this is mandatory for creating port bindings after creating sub-processes send_message
(message, address, stream[, …])sendMessage general from service start
(_params[, _internal])SocketService start function starts a specific socket service and binds the ports stop
()Stops a service immediately Methods Documentation
-
add_accept_handler
(sock, callback)¶ Accept Handler for UDP Socket
Parameters: - {socket} -- Socket object (sock) –
- {function} -- callBackFunction (callback) –
Keyword Arguments: {IOLoop Obj} -- Current IOLoop (default (io_loop) – {None})
-
add_sockets
(sockets)¶ Adds speficic sockets to the server
Parameters: {[Dict]} -- Dict of Sockets (sockets) –
-
bind
(port, address=None, family=<AddressFamily.AF_UNSPEC: 0>)¶ Bind a specific socket (here UDP) to the server
Parameters: {int} -- [port number] (port) –
Keyword Arguments: - {string} -- [Address string] (default (address) – {None})
- {Socket.Family} -- [Socket.Family] (default (family) – {socket.AF_UNSPEC})
- {int} -- [description] (default (backlog) – {25})
-
bind_unix_socket
(file, mode)¶ Special binding for UnixSockets - the way unix-sockets are reused depends extremly on OS Platform
Parameters: - {string} -- file name (file) –
- {int} -- chmod mode (mode) –
Keyword Arguments: {int} -- current backlog (default (backlog) – {128})
Returns: Socket obj – the current socket
-
static
can_send
()¶ Basic info wether service can send back or not
Returns: bool – can send back?
-
close
()¶ Basic close service
-
static
get_service
(_params, _server=None)¶ Gets a service from service params EXAMPLE: _params[‘active_service’].append({
# tcp service “id”: 2, “antano_server_id”: 1, # needs to be the same as id above “service_type_id”: 2, “port”: 18002, “host”: “0.0.0.0”, “endpoint”: “”, # in case of rest or websocket /my_endpoint put “my_endpoint” “message_format_in_id”: 1, # message_format “message_format_out_id”: 1, # message_format})
Parameters: {Dict<String, Obj>} -- service param (_params) – Returns: Service obj – a service
-
on_received_message
(message, address, sock_stream)¶ On received message will process the message and if there is a repsonse it will send back to the same stream the client has send
Parameters: - {bytes[]} -- message data (message) –
- {Tuple (address) –
- {mixed} -- Socket or SOCK_STREAM (sock) –
Returns: [bytes[]] – response
-
static
run_processes
(_services, _num_of_process)¶ Finally runs all processes for given sockets this is mandatory for creating port bindings after creating sub-processes
Parameters: - {array} -- array of services (_services) –
- {int} -- number of processes to start (_num_of_process) –
-
send_message
(message, address, stream, is_binary=False)¶ sendMessage general from service
Parameters: - {bytes[]} -- Current message data to send (message) –
- {Tuple<String,Int>} -- IP address and port (address) –
- {IOStream} -- Current client stream (stream) –
- -- bool is bytes or dict (is_binary) –
-
start
(_params, _internal=False)¶ SocketService start function starts a specific socket service and binds the ports
Parameters: - {string} -- ip or host (_ip) –
- {int} -- defined port (_port) –
-
stop
()¶ Stops a service immediately
-