本文整理汇总了Python中socket.socket.connect函数的典型用法代码示例。如果您正苦于以下问题:Python connect函数的具体用法?Python connect怎么用?Python connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connect函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:B-Rich,项目名称:edk2,代码行数:27,代码来源:ssl.py
示例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()
开发者ID:PatrickDattilio,项目名称:TEC-Client,代码行数:33,代码来源:client.py
示例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')
开发者ID:chidea,项目名称:rebauth,代码行数:25,代码来源:ServerSocket.py
示例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()
开发者ID:Errorprone85,项目名称:TEC-Client,代码行数:34,代码来源:client.py
示例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()
开发者ID:connoryang,项目名称:dec-eve-serenity,代码行数:7,代码来源:ssl.py
示例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
开发者ID:oksome,项目名称:Intercom,代码行数:11,代码来源:minion.py
示例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()
开发者ID:maximerobin,项目名称:Ufwi,代码行数:12,代码来源:ssl.py
示例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
开发者ID:bizonix,项目名称:DropBoxLibrarySRC,代码行数:16,代码来源:ssl.py
示例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
开发者ID:Badcreature,项目名称:sagcg,代码行数:17,代码来源:ssl.py
示例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
开发者ID:595171801,项目名称:SublimeText2-FTPSync,代码行数:20,代码来源:ssl.py
示例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
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:20,代码来源:ssl.py
示例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
开发者ID:webiumsk,项目名称:WOT-0.9.14-CT,代码行数:20,代码来源:ssl.py
示例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
开发者ID:NickolasLapp,项目名称:wolfssl,代码行数:21,代码来源:__init__.py
示例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
开发者ID:alej0varas,项目名称:pythones,代码行数:22,代码来源:ssl.py
示例15: connect
def connect(self, *args, **kwargs):
time.sleep(random.random() * seconds)
return _socket.connect(self, *args, **kwargs)
开发者ID:bossjones,项目名称:mrq,代码行数:3,代码来源:monkey.py
示例16: connect
def connect(self, address):
socket.connect(self, address)
socket.setsockopt(self, IPPROTO_TCP, TCP_NODELAY, 1)
raw_send = self.send
def send_x(data, timeout=0):
view = memoryview(data)
size = len(view)
offset = 0
while offset < size:
_, ready_to_write, _ = select((), (self,), (), timeout)
while not ready_to_write:
_, ready_to_write, _ = select((), (self,), (), timeout)
sent = raw_send(view[offset:])
if sent == 0:
raise SocketError("Peer closed connection")
offset += sent
raw_recv = self.recv
received = [b""] # the functions below assume exactly one item in this list on entry and exit
def recv_headers(timeout=0):
end = received[0].find(b"\r\n\r\n")
while end == -1:
ready_to_read, _, _ = select((self,), (), (), timeout)
while not ready_to_read:
ready_to_read, _, _ = select((self,), (), (), timeout)
data = raw_recv(8192)
received[0] += data
end = received[0].find(b"\r\n\r\n")
if data == b"" and end == -1:
raise SocketError("Peer closed connection")
data, received[0] = received[0][:end], received[0][(end + 4):]
return data.split(b"\r\n")
def recv_content(length=None, timeout=0):
if length is None:
# receive until closed
if received[0]:
yield received[0]
received[0] = b""
more = True
while more:
ready_to_read, _, _ = select((self,), (), (), timeout)
while not ready_to_read:
ready_to_read, _, _ = select((self,), (), (), timeout)
data = raw_recv(8192)
if data == b"":
more = False
else:
yield data
else:
assert length >= 0
# receive fixed amount
while length != 0:
data, received[0] = received[0][:length], received[0][length:]
size = len(data)
if size != 0:
yield data
length -= size
if length != 0:
ready_to_read, _, _ = select((self,), (), (), timeout)
while not ready_to_read:
ready_to_read, _, _ = select((self,), (), (), timeout)
data = raw_recv(8192)
if data == b"":
raise SocketError("Peer closed connection")
received[0] += data
def recv_line(timeout=0):
end = received[0].find(b"\r\n")
while end == -1:
ready_to_read, _, _ = select((self,), (), (), timeout)
while not ready_to_read:
ready_to_read, _, _ = select((self,), (), (), timeout)
data = raw_recv(8192)
received[0] += data
end = received[0].find(b"\r\n")
if data == b"" and end == -1:
raise SocketError("Peer closed connection")
data, received[0] = received[0][:end], received[0][(end + 2):]
return data
def recv_exact(length, timeout=0):
available = len(received[0])
while available < length:
ready_to_read, _, _ = select((self,), (), (), timeout)
while not ready_to_read:
ready_to_read, _, _ = select((self,), (), (), timeout)
data = raw_recv(8192)
received[0] += data
available += len(data)
if data == b"" and available < length:
raise SocketError("Peer closed connection")
data, received[0] = received[0][:length], received[0][length:]
return data
def recv_chunked_content(timeout=0):
chunk_size = -1
#.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:httq,代码行数:101,代码来源:httq.py
注:本文中的socket.socket.connect函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论