Table Of Contents

Previous topic

ginsfsm.c_sock

Next topic

ginsfsm.c_connex

ginsfsm.c_srv_sock

GObj GServerSock

GObj for manage server socket.

class ginsfsm.c_srv_sock.GServerSock[source]

GSock gobj acting as server sock.

This gobj is derived from ginsfsm.c_sock.GSock, but it uses the server behaviour of a sock. It creates a listening sock at configured (host, port) attributes.

GServerSock can serve SSL traffic with Python 2.6+ and OpenSSL. To make this server serve SSL traffic, send the ssl_options dictionary argument with the arguments required for the ssl.wrap_socket method, including “certfile” and “keyfile”:

ssl_options={
    "certfile": os.path.join(data_dir, "mydomain.crt"),
    "keyfile": os.path.join(data_dir, "mydomain.key"),
}

Each incoming connection will create a new ginsfsm.c_sock.GSock gobj, that it will be child of the subscriber gobj (the parent by default).

Note

Once an 'EV_CONNECTED' event has been sent, the GServerSock doesn’t know anything more of the new gsock client.

The relationship is directly between the accepted ginsfsm.c_sock.GSock gobj and the subscriber.

The subcriber is responsible of receiving all events and destroy the new gsock client.

Warning

Remember to destroy the accepted gobj with destroy_gobj() when the gobj has been disconnected.

The subcriber knows when a new gobj has been accepted because it receives the 'EV_CONNECTED' event.

When the subcriber receives a 'EV_DISCONNECTED' event must destroy the gobj because the connection ceases to exist.

Configurable Parameters:
Name Type Default value Description
ports tuple () multi ports
subscriber None None subcriber of all output-events.Default is None, i.e., the parent
host str server host (ip or name)
use_multi_ports bool False use multi ports
n_gsocks int 0 Server Stats: Number of gsocks opened
port int 0 server port
ssl_options dict {} ssl options
Diagram:
Output-Events:
  • 'EV_CONNECTED': new client socket connected.

    The gobj sending the ‘EV_CONNECTED’ event is the new client socket gobj.

    Attributes added to the sent event:

    • peername: remote address to which the socket is connected.
    • sockname: the socket’s own address.

    The subscriber can know from which server comes the client by the name of client gobj.

    If the server gobj has name, the name of client gobj will be: ‘server-name.clisrv_#’

start_up()[source]

Initialization zone.

Subscribe all events to parent if subscriber is None.

Start listen to (host,port).