    <class name="NetworkServerSocket">
        <constructor>
            <parameter name="my_socket"/>
            <body>
                <![CDATA[
                self.socket = my_socket
                self.received_data = ""
                self.send_data = None
                self.association_name = None
                self.queue = []
                ]]>
            </body>
        </constructor>
        <scxml initial="parallel">
            <parallel id="parallel">
                <!-- We explicitly use the fact that there is no threading -->
                <state id="processing" initial="processing">
                    <state id="processing">
                        <transition cond="'\0' in self.received_data" target=".">
                            <script>
                                self.parsing_data, self.received_data = self.received_data.split('\0', 1)
                            </script>
                            <raise scope="broad" event="server_output">
                                <parameter expr="self.socket"/>
                                <parameter expr="self.parsing_data"/>
                            </raise>
                        </transition>
                    </state>
                </state>

                <state id="receiving">
                    <state id="receive">
                        <onentry>
                            <raise scope="output" event="recv_socket" output="socket_out">
                                <parameter expr="self.socket"/>
                            </raise>
                        </onentry>
                        <transition port="socket_in" event="received_socket" cond="self.socket == socket and data != ''" target=".">
                            <parameter name="socket"/>
                            <parameter name="data"/>
                            <script>
                                self.received_data += data
                            </script>
                        </transition>
                        <transition port="socket_in" event="received_socket" cond="self.socket == socket and data == ''" target=".">
                            <parameter name="socket"/>
                            <parameter name="data"/>
                            <raise event="stop"/>
                        </transition>
                    </state>
                </state>

                <state id="sending" initial="waiting_for_inputdata">
                    <state id="waiting_for_inputdata">
                        <transition cond="len(self.queue) > 0" target="../transmitting">
                            <script>
                                self.send_data = self.queue.pop(0) + "\0"
                            </script>
                        </transition>
                    </state>

                    <state id="transmitting">
                        <onentry>
                            <raise scope="output" event="send_socket" output="socket_out">
                                <parameter expr="self.socket"/>
                                <parameter expr="self.send_data"/>
                            </raise>
                        </onentry>
                        <transition port="socket_in" cond="self.socket == socket and (sent == len(self.send_data))" event="sent_socket" target="../waiting_for_inputdata">
                            <parameter name="socket"/>
                            <parameter name="sent"/>
                            <script>
                                self.send_data = ""
                            </script>
                        </transition>
                        <transition port="socket_in" cond="self.socket == socket and (sent != len(self.send_data))" event="sent_socket" target=".">
                            <parameter name="socket"/>
                            <parameter name="sent"/>
                            <script>
                                self.send_data = self.send_data[sent:]
                            </script>
                        </transition>
                    </state>
                </state>

                <state id="receiver">
                    <state id="queue">
                        <transition event="server_input" cond="self.socket == socket" target=".">
                            <parameter name="socket"/>
                            <parameter name="data"/>
                            <script>
                                self.queue.append(data)
                            </script>
                        </transition>
                    </state>
                </state>

                <transition event="stop" target="../close"/>
            </parallel>

            <state id="close">
                <onentry>
                    <raise scope="output" event="close_socket" output="socket_out">
                        <parameter expr="self.socket"/>
                    </raise>
                </onentry>
            </state>
        </scxml>
    </class>
