本文整理汇总了Python中socket.socket.connect函数的典型用法代码示例。如果您正苦于以下问题:Python connect函数的具体用法?Python connect怎么用?Python connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _real_connect
def _real_connect(self, addr, return_errno):
# Here we assume that the socket is client-side, and not
# connected at the time of the call. We connect it, then wrap it.
if self._connected:
raise ValueError("attempt to connect already-connected SSLSocket!")
self._sslobj = _ssl.sslwrap(
self._sock,
False,
self.keyfile,
self.certfile,
self.cert_reqs,
self.ssl_version,
self.ca_certs,
self.ciphers,
)
try:
socket.connect(self, addr)
if self.do_handshake_on_connect:
self.do_handshake()
except socket_error as e:
if return_errno:
return e.errno
else:
self._sslobj = None
raise e
self._connected = True
return 0
示例2: listen
def listen(self):
socket.connect(self.socket, ("tec.skotos.net", 6730))
self.login_user()
if self.connect:
self.send("SKOTOS Zealous 0.7.12.2\n")
while self.connect:
buffer = ""
sleep(0)
try:
buffer = str(self.socket.recv(4096), encoding='utf8')
except Exception as exc:
pass
buffer = buffer.splitlines()
if not buffer.__len__() == 0:
for number, line in enumerate(buffer):
if line.find('SECRET') == -1:
self.ui.parse_output(line)
else:
if line.find('SECRET') == 0:
secret = line[7:].strip()
hash_string = self.uname + self.pwd + secret
zealous_hash = hashlib.md5(hash_string.encode('utf-8')).hexdigest()
self.send("USER " + self.uname)
self.send("SECRET " + secret)
self.send("HASH " + zealous_hash)
self.send("CHAR ")
# After a Zealotry login the server still sends a password prompt. This just responds to
# that with a dummy entry.
self.send("Nope")
else:
break
if self.connect:
self.shutdown()
示例3: __init__
def __init__(self,db):
self._ipcPath=db.getSettingPath()
SocketlikeIPC.__init__(self, self._ipcPath)
# super(type(self),self).__init__(self._ipcPath)
# if super(type(self),self)._connect():
if SocketlikeIPC._connect(self):
print('IPC connect succeed. Welcome back, administrator.')
return
print('IPC failed. proceeding with TCP.')
super(type(self)) #unbound
socket.__init__(self)
try:
socket.connect(self,('racu.idea.sh', PortEnum.MAIN_SERVER.value))
lastPin = db.getConfig()
print('lastPin =', lastPin, len(lastPin))
pinmsg = int.to_bytes(SocketEnum.PIN.value, 1, 'big') + int.to_bytes(lastPin[0]) if 10**3<=lastPin['lastPIN']<10**4 else b''
msg = ''
# while not msg:
socket.sendall(self,pinmsg)
msg = socket.recv(self)
if not msg:
print('main server connect error')
return
except:
print('main server connect error')
示例4: listen
def listen(self):
pprint("Starting connection!")
socket.connect(self.socket, ("tec.skotos.net", 6730))
self.login_user()
self.send("SKOTOS Zealous 0.7.12.2\n")
while self.connect:
buffer = ""
sleep(0)
try:
buffer = str(self.socket.recv(4096), encoding='utf8')
except Exception as exc:
pprint(exc.args)
pprint("SOMETHING BAD HAPPENED")
buffer = buffer.splitlines()
if not buffer.__len__() == 0:
for number, line in enumerate(buffer):
if line.find('SECRET') == -1:
self.ui.parse_output(line)
else:
if line.find('SECRET') == 0:
secret = line[7:].strip()
pprint(self.uname + self.pwd + secret)
hash_string = self.uname + self.pwd + secret
zealous_hash = hashlib.md5(hash_string.encode('utf-8')).hexdigest()
pprint(zealous_hash)
self.send("USER " + self.uname)
self.send("SECRET " + secret)
self.send("HASH " + zealous_hash)
self.send("CHAR ")
else:
pprint(buffer)
break
if self.connect:
self.shutdown()
示例5: connect
def connect(self, addr):
if self._sslobj:
raise ValueError('attempt to connect already-connected SSLSocket!')
socket.connect(self, addr)
self._sslobj = _ssl.sslwrap(self._sock, False, self.keyfile, self.certfile, self.cert_reqs, self.ssl_version, self.ca_certs, self.ciphers)
if self.do_handshake_on_connect:
self.do_handshake()
示例6: send
def send(self, topic, msg):
if type(topic) != bytes:
topic = bytes(str(topic), 'utf-8')
messagedata = bytes(json.dumps(msg), 'utf-8')
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect(self._relay_in)
socket.send(topic + b' ' + messagedata)
reply = socket.recv()
assert reply
示例7: connect
def connect(self, addr):
"""Connects to remote ADDR, and then wraps the connection in
an SSL channel."""
# Here we assume that the socket is client-side, and not
# connected at the time of the call. We connect it, then wrap it.
if self._sslobj:
raise ValueError("attempt to connect already-connected SSLSocket!")
socket.connect(self, addr)
self._sslobj = _ssl.ssl(self._sock, self.keyfile, self.certfile)
self.do_handshake()
示例8: _real_connect
def _real_connect(self, addr, return_errno):
if self._connected:
raise ValueError('attempt to connect already-connected SSLSocket!')
self._sslobj = _ssl.sslwrap(self._sock, False, self.keyfile, self.certfile, self.cert_reqs, self.ssl_version, self.ca_certs, self.ciphers, self.ca_certs_string)
try:
socket.connect(self, addr)
if self.do_handshake_on_connect:
self.do_handshake()
except socket_error as e:
if return_errno:
return e.errno
self._sslobj = None
raise e
self._connected = True
return 0
示例9: connect
def connect(self, addr):
"""Connects to remote ADDR, and then wraps the connection in
an SSL channel."""
if self.server_side:
raise ValueError("can't connect in server-side mode")
# Here we assume that the socket is client-side, and not
# connected at the time of the call. We connect it, then wrap it.
if self._sslobj:
raise ValueError("attempt to connect already-connected SSLSocket!")
socket.connect(self, addr)
self._sslobj = self.context._wrap_socket(self, False, self.server_hostname)
try:
if self.do_handshake_on_connect:
self.do_handshake()
except:
self._sslobj = None
raise
示例10: _real_connect
def _real_connect(self, addr, return_errno):
if self.server_side:
raise ValueError("can't connect in server-side mode")
# Here we assume that the socket is client-side, and not
# connected at the time of the call. We connect it, then wrap it.
if self._connected:
raise ValueError("attempt to connect already-connected SSLSocket!")
self._sslobj = self.context._wrap_socket(self, False, self.server_hostname)
try:
socket.connect(self, addr)
if self.do_handshake_on_connect:
self.do_handshake()
except socket_error as e:
if return_errno:
return e.errno
else:
self._sslobj = None
raise e
self._connected = True
return 0
示例11: _real_connect
def _real_connect(self, addr, connect_ex):
if self.server_side:
raise ValueError("can't connect in server-side mode")
if self._connected:
raise ValueError('attempt to connect already-connected SSLSocket!')
self._sslobj = self.context._wrap_socket(self, False, self.server_hostname)
try:
if connect_ex:
rc = socket.connect_ex(self, addr)
else:
rc = None
socket.connect(self, addr)
if not rc:
if self.do_handshake_on_connect:
self.do_handshake()
self._connected = True
return rc
except socket_error:
self._sslobj = None
raise
示例12: _real_connect
def _real_connect(self, addr, return_errno):
if self._connected:
raise ValueError('attempt to connect already-connected SSLSocket!')
self._sslobj = _ssl.sslwrap(self._sock, False, self.keyfile, self.certfile, self.cert_reqs, self.ssl_version, self.ca_certs, self.ciphers)
try:
if return_errno:
rc = socket.connect_ex(self, addr)
else:
rc = None
socket.connect(self, addr)
if not rc:
if self.do_handshake_on_connect:
self.do_handshake()
self._connected = True
return rc
except socket_error:
self._sslobj = None
raise
return
示例13: _real_connect
def _real_connect(self, addr, connect_ex):
if self.server_side:
raise ValueError("can't connect in server-side mode")
# Here we assume that the socket is client-side, and not
# connected at the time of the call. We connect it, then wrap it.
if self._connected:
raise ValueError("attempt to connect already-connected SSLSocket!")
if connect_ex:
err = socket.connect_ex(self, addr)
else:
err = 0
socket.connect(self, addr)
if err == 0:
self._connected = True
if self.do_handshake_on_connect:
self.do_handshake()
return err
示例14: _real_connect
def _real_connect(self, addr, connect_ex):
if self.server_side:
raise ValueError("can't connect in server-side mode")
# Here we assume that the socket is client-side, and not
# connected at the time of the call. We connect it, then wrap it.
if self._connected:
raise ValueError("attempt to connect already-connected SSLSocket!")
self._sslobj = self.context._wrap_socket(self, False, self.server_hostname)
try:
if connect_ex:
rc = socket.connect_ex(self, addr)
else:
rc = None
socket.connect(self, addr)
if not rc:
if self.do_handshake_on_connect:
self.do_handshake()
self._connected = True
return rc
except OSError:
self._sslobj = None
raise
示例15: connect
def connect(self, *args, **kwargs):
time.sleep(random.random() * seconds)
return _socket.connect(self, *args, **kwargs)