    <class name="NetworkServer" default="true">
        <relationships>
            <association name="sockets" class="NetworkServerSocket" />
        </relationships>
        <constructor>
            <parameter name="port"/>
            <body>
                <![CDATA[
                self.socket = None
                self.association_name = None
                self.port = port
                ]]>
            </body>
        </constructor>
        <scxml initial="init">
            <state id="init">
                <transition event="set_association_name" target="../main">
                    <parameter name="association_name"/>
                    <script>
                        self.association_name = association_name
                    </script>
                </transition>
            </state>
            <parallel id="main">
                <state id="main" initial="init">
                    <state id="init">
                        <onentry>
                            <raise scope="output" event="create_socket" port="socket_out"/>
                        </onentry>
                        <transition port="socket_in" event="created_socket" target="../binding">
                            <parameter name="socket"/>
                            <script>
                                self.socket = socket
                            </script>
                        </transition>
                    </state>
                    <state id="binding">
                        <onentry>
                            <raise scope="output" event="bind_socket" port="socket_out">
                                <parameter expr="self.socket"/>
                                <parameter expr="('0.0.0.0', self.port)"/>
                            </raise>
                        </onentry>
                        <transition port="socket_in" event="bound_socket" cond="self.socket == socket" target="../listening">
                            <parameter name="socket"/>
                        </transition>
                    </state>
                    <state id="listening">
                        <onentry>
                            <raise scope="output" event="listen_socket" port="socket_out">
                                <parameter expr="self.socket"/>
                            </raise>
                        </onentry>
                        <transition port="socket_in" event="listened_socket" cond="self.socket == socket" target="../accepting">
                            <parameter name="socket"/>
                        </transition>
                    </state>
                    <state id="accepting">
                        <onentry>
                            <raise scope="output" port="socket_out" event="accept_socket">
                                <parameter expr="self.socket"/>
                            </raise>
                        </onentry>
                        <transition port="socket_in" event="accepted_socket" cond="self.socket == socket" target=".">
                            <parameter name="socket"/>
                            <parameter name="connected_socket"/>
                            <raise scope="cd" event="create_instance">
                                <parameter expr="'sockets'" />
                                <parameter expr="'NetworkServerSocket'" />
                                <parameter expr="connected_socket" />
                            </raise>
                        </transition>
                        <transition event="instance_created" target=".">
                            <parameter name="instancename"/>
                            <raise scope="narrow" event="set_association_name" target="instancename">
                                <parameter expr="instancename"/>
                            </raise>
                            <raise scope="cd" event="start_instance">
                                <parameter expr="instancename" />
                            </raise>
                        </transition>
                    </state>
                </state>
                <state id="close">
                    <state id="close">
                        <transition event="close" target=".">
                            <raise scope="cd" event="delete_instance">
                                <parameter expr="association_name"/>
                            </raise>
                        </transition>
                    </state>
                </state>
            </parallel>
        </scxml>
    </class>
