def run(self):
     log.info('Running server on port %d' % self.port)
     rpcprotocol = RPCProtocol()
     self.tcpserver = TCPServer(self.handler,rpcprotocol)
     self.tcpserver.bind(self.port, self.host)
     self.tcpserver.start(0)
     ioloop.IOLoop.instance().start()
示例#2
0
    def start_server(self):
        if not self.is_server_started:
            self.is_server_started = True
            port = 12017
            server_backlog = 10
            send_hz = 10
            ip_list = self.model.teams_list.keys()
            self.server = TCPServer(port,
                                    server_backlog,
                                    whitelist=ip_list,
                                    hz=send_hz)
            self.server.new_connection.connect(
                self.model.new_connection_handler)
            self.server.lost_connection.connect(
                self.model.lost_connection_handler)
            self.server.new_response.connect(self.model.new_response_handler)

            self.server.server_ready.connect(self.server_ready_handler)

            self.model.team_state_change_signal.connect(
                self.server.on_race_state_change)

            self.server_thread = QThread()
            self.server.moveToThread(self.server_thread)
            self.server_thread.started.connect(self.server.run_server)
            self.server_thread.start()
示例#3
0
    def on_tcp_server_start_stop_button_clicked(self):
        if self.ui.button_TcpServer.text() == 'Start':
            self.ui.button_TcpServer.setEnabled(False)
            self.ui.lineEdit_TcpServerListenPort.setEnabled(False)
            self.tcp_server_thread = QThread()
            self.tcp_server = TCPServer(
                self.ui.label_LocalIP.text(),
                int(self.ui.lineEdit_TcpServerListenPort.text()))

            self.tcp_server_thread.started.connect(self.tcp_server.start)
            self.tcp_server.status.connect(self.on_tcp_server_status_update)
            self.tcp_server.message.connect(self.on_tcp_server_message_ready)

            self.tcp_server.moveToThread(self.tcp_server_thread)

            self.tcp_server_thread.start()

            self.config['TCP_Server_Port'] = self.ui.lineEdit_TcpServerListenPort.text()
            self.save_config()

        elif self.ui.button_TcpServer.text() == 'Stop':
            self.ui.button_TcpServer.setEnabled(False)
            self.tcp_server.close()

        elif self.ui.button_TcpServer.text() == 'Disconnect':
            self.ui.button_TcpServer.setEnabled(False)
            self.tcp_server.disconnect()
示例#4
0
# mohoque

from tcpserver import TCPServer

if __name__ == "__main__":

    serverAddr = '127.0.0.1'
    port = 8080
    d = TCPServer(serverAddr, port)
    d.start_server()
# An example showing the use of httpserver.TCPServer
# Reverses the data received from the client and send it back

import sys

# Import httpserver in the python import path
sys.path.insert(0, "./httpserver")

from tcpserver import TCPServer


def reverse_data(queue, data):
    queue.put(data[::-1])
    print(data)


if __name__ == '__main__':
    server = TCPServer('127.0.0.1', 8000, callback=reverse_data)
    server.start()
    server.run()