示例#1
0
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)

        self.layout = QVBoxLayout()
        self.setLayout(self.layout)

        self.address = QLineEdit()
        self.address.setInputMask("\A\d\dress: 000.000.000.000")
        self.address.setText('192.168.001.069')
        self.port = QLineEdit()
        self.port.setInputMask("Port: 9000")
        self.port.setText('9110')
        self.btnConnect = QPushButton()
        self.btnConnect.clicked.connect(self.btnConnectClicked)

        self.statusBar = QStatusBar()

        self.layout.addWidget(self.address)
        self.layout.addWidget(self.port)
        self.layout.addWidget(self.btnConnect)
        self.layout.addWidget(self.statusBar)

        self.tcpClient = TcpClient()

        self.setWindowTitle('CAN Printer Logger v.{}'.format(self.version))
        self.setWindowIcon(QIcon('icons/icon.png'))


        self.tcpClient.connectionFailed.connect(self.connectionFailed)
        self.tcpClient.tcpClientError.connect(self.connectionFailed)
        self.tcpClient.connected.connect(self.connected)
        self.tcpClient.disconnected.connect(self.disconnected)
        self.changeState(self.stDisconnected)
示例#2
0
文件: mala.py 项目: kun1989/rl-slg
 def __init__(self, user_name, debug=False):
     self.logger = add_log('mala_%s' % user_name, debug)
     self.user_id = 0
     self.user_name = user_name
     self.tcp_client = TcpClient(self)
     self.tcp_client.setDaemon(True)
     self.tcp_client.start()
     self.user_data = None
     self.action_state = 0
     self.enabled_actions = ['build', 'army', 'fast_forward']
示例#3
0
#线程类
class keyBordInput(threading.Thread):
    def __init__(self, sock):
        threading.Thread.__init__(self)
        self._sock = sock

    def run(self):
        print('input \'quit\' to exit!')
        while True:
            msg = input(str(self._sock.localAdr) + ':')
            if msg == 'quit' or self._sock._closed:
                break
            self._sock.send(msg)
        self._sock.close()


'''
    普通的客户端程序
'''
if __name__ == "__main__":
    IP = '169.254.252.124'
    port = 6000
    client = TcpClient()
    client.connect(IP, port)
    #建立线程,用于接收键盘输入
    th = keyBordInput(client)
    th.start()
    client.receive()
    print('remote server closed connection! press any key to exit!')
    th.join()
    print('client is closed!')
示例#4
0
 def __init__(self, parent=None):
     QWidget.__init__(self, parent)
     self.setupUi(self)
     self.tcp_client = TcpClient()