def onTimer(self): if -1 == self.connected: zokket.TCPSocket(self).connect(host='127.0.0.1', port=8601, timeout=4) self.connected = 0 self.editor.append("Connecting to 127.0.0.1:8601 ...")
def onTimer(self, timer): if -1 == self.connected: zokket.TCPSocket(self).connect(host='127.0.0.1', port=8601, timeout=4) self.connected = 0 print("Reconnecting to 127.0.0.1:8601 ...")
def connect(self): if len(self.portrange) == 0: zokket.DefaultRunloop.abort() return s = zokket.TCPSocket(self) s.connect(self.target, self.portrange.pop(0), timeout=self.timeout)
def __init__(self): zokket.Timer(1, self.onTimer, True) self.connected = -1 # -1 disconnected, 0 connecting, 1 connected. zokket.TCPSocket(self).connect(host='127.0.0.1', port=8601, timeout=4) self.connected = 0 print("Connecting to 127.0.0.1:8601 ...")
def on_btnConnectSvr_clicked(self): """ Slot documentation goes here. """ if self.connected: return pwd = self.editPwd.text() if len(pwd) < 1: self.insertEditInfo(u'加密密钥不能为空!') return self.pwd = base64.b64encode(str(pwd.toUtf8())) self.editPwd.setText(u'*' * 18) chid = self.editChid.text() if len(chid) < 1: self.insertEditInfo(u'用户名称不能为空!') return self.chid = str(chid.toUtf8()) #print 'self.chid=', self.chid svrAddr = str(self.editSvrAddr.text().toUtf8()) if len(svrAddr) > 0: r = svrAddr.split(':') if len(r) > 0: self.host = r[0] if len(r) > 1: self.port = int(r[1]) self.insertEditInfo(u"使用输入的服务地址, %s:%d" % (self.host.decode('utf-8'), self.port)) else: self.host = '' if len(self.host) < 1 or self.port < 1: # Use default. self.insertEditInfo(u"[%s] 正在获取服务ip, 请稍候..." % (self.formatTime(self.timeNow()))) try: self.getHostFromGithub() except: self.insertEditInfo( u"[%s] 获取服务地址失败, %s:%d" % (self.formatTime(self.timeNow()), self.host, self.port)) if len(self.host) > 0 and self.port > 0: zokket.TCPSocket(self).connect(host=self.host, port=self.port, timeout=12) self.insertEditInfo( u"[%s] 正在连接 %s:%d ..." % (self.formatTime(self.timeNow()), self.host, self.port)) self.btnConnectSvr.enable = False
def send(self, server, tcp=False, questions=[]): packet = Packet(int(random.random() * 1000), questions=questions) payload = bytes(packet) if tcp: sock = zokket.TCPSocket(self) sock.connect(server, 53) sock.read_until_length = 2 sock.buffer_type = None self.payload = payload else: sock = zokket.UDPSocket(self) sock.bind() sock.send(server, 53, payload)
def __init__(self): super(Window, self).__init__() self.setWindowTitle('zokket - PyQT Example') self.editor = QtGui.QTextEdit() self.editor.setReadOnly(True) self.setCentralWidget(self.editor) self.resize(500, 300) self.show() # Lets connect to duckduckgo.com zokket.TCPSocket(self).connect(host='duckduckgo.com', port=443, timeout=15) self.editor.append("Connecting to duckduckgo.com...")
def __init__(self): super(Window, self).__init__() self.setWindowTitle('zokket - PyQT Example') self.editor = QtGui.QTextEdit() self.editor.setReadOnly(True) self.setCentralWidget(self.editor) self.resize(500, 300) self.show() # create timer self.timer = QtCore.QTimer() QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout()"), self.onTimer) self.timer.start(1000) self.connected = -1 # -1 disconnected, 0 connecting, 1 connected. zokket.TCPSocket(self).connect(host='127.0.0.1', port=8601, timeout=4) self.connected = 0 self.editor.append("Connecting to 127.0.0.1:8601...")
def __init__(self): # Lets connect to duckduckgo.com zokket.TCPSocket(self).connect(host='duckduckgo.com', port=443)
def __init__(self): zokket.TCPSocket(self).accept(port=5000)
def __init__(self): super(EchoServerFrame, self).__init__(None, -1, 'EchoServer') self.text = wx.TextCtrl(self, -1, '', style=wx.TE_MULTILINE) # Lets listen on port 5000 zokket.TCPSocket(self).accept(port=5000)