def __init__(self): super().__init__() super(QtWidgets.QMainWindow, self).__init__() self.status_message = ['● Idle', '● Idle', '● Idle', ''] config_file = Path('config.json') # config_file = open('config.json', 'w+') if config_file.exists(): self.config = json.load(open('config.json', 'r')) else: self.config = dict() json.dump(self.config, open('config.json', 'w+')) """Load UI""" self.ui = uic.loadUi('mainwindow.ui', self) self.init_ui() self.ui.comboBox_Interface.currentIndexChanged.connect( self.on_interface_selection_change) self.ui.button_Refresh.clicked.connect(self.on_refresh_button_clicked) self.ui.button_TcpClient.clicked.connect( self.on_tcp_client_connect_button_clicked ) self.ui.button_TcpClientSend.clicked.connect( self.on_tcp_client_message_send ) self.ui.lineEdit_TcpClientSend.returnPressed.connect( self.on_tcp_client_message_send ) self.ui.button_TcpServer.clicked.connect( self.on_tcp_server_start_stop_button_clicked) self.ui.button_TcpServerSend.clicked.connect( self.on_tcp_server_message_send ) self.ui.lineEdit_TcpServerSend.returnPressed.connect( self.on_tcp_server_message_send ) self.ui.button_Udp.clicked.connect( self.on_udp_server_start_stop_button_clicked ) self.ui.button_UdpSend.clicked.connect( self.on_udp_message_send ) self.ui.lineEdit_UdpSend.returnPressed.connect( self.on_udp_message_send ) self.udp_send = UDPServer( '0.0.0.0', 1234) self.ui.tabWidget.currentChanged.connect( self.on_tab_changed )
def on_udp_server_start_stop_button_clicked(self): if self.ui.button_Udp.text() == 'Start': self.ui.button_Udp.setEnabled(False) self.ui.lineEdit_UdpListenPort.setEnabled(False) self.udp_thread = QThread() self.udp_server = UDPServer( self.ui.label_LocalIP.text(), int(self.ui.lineEdit_UdpListenPort.text())) self.udp_thread.started.connect(self.udp_server.start) self.udp_server.status.connect(self.on_udp_server_status_update) self.udp_server.message.connect(self.on_udp_server_message_ready) self.udp_server.moveToThread(self.udp_thread) self.udp_thread.start() self.config['UDP_Listen_Port'] = self.ui.lineEdit_UdpListenPort.text() self.save_config() elif self.ui.button_Udp.text() == 'Stop': self.ui.button_Udp.setEnabled(False) self.udp_server.close()
def server(): TCPServer() UDPServer()
def run_tcp_server(tcp_obj): server.register_instance(tcp_obj) server.serve_forever() if __name__ == '__main__': logging.basicConfig(filename='mp3.log',level=logging.INFO, filemode='w') os.system("rm sdfs/*") console = logging.StreamHandler() console.setLevel(logging.DEBUG) logging.getLogger('').addHandler(console) sdfs_master = SDFS_Master() slave = Slave(logging, sdfs_master) udpserver = UDPServer(slave) udpserver.run_server() slave.run() cli = CLI(slave, logging) cli.run() slave.init_join() tcpserver = TCPServer(slave, sdfs_master, logging) run_tcp_server(tcpserver)
def initialize_udp(slave): udpserver = UDPServer(slave) return udpserver