本文整理汇总了Python中socket.socket.close方法的典型用法代码示例。如果您正苦于以下问题:Python socket.close方法的具体用法?Python socket.close怎么用?Python socket.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类socket.socket
的用法示例。
在下文中一共展示了socket.close方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_server_certificate
# 需要导入模块: from socket import socket [as 别名]
# 或者: from socket.socket import close [as 别名]
def get_server_certificate(addr, ssl_version=PROTOCOL_SSLv3, ca_certs=None):
"""Retrieve the certificate from the server at the specified address,
and return it as a PEM-encoded string.
If 'ca_certs' is specified, validate the server cert against it.
If 'ssl_version' is specified, use it in the connection attempt."""
host, port = addr
if (ca_certs is not None):
cert_reqs = CERT_REQUIRED
else:
cert_reqs = CERT_NONE
s = wrap_socket(socket(), ssl_version=ssl_version,
cert_reqs=cert_reqs, ca_certs=ca_certs)
s.connect(addr)
dercert = s.getpeercert(True)
s.close()
return DER_cert_to_PEM_cert(dercert)
示例2: accept
# 需要导入模块: from socket import socket [as 别名]
# 或者: from socket.socket import close [as 别名]
def accept(self):
"""Accepts a new connection from a remote client, and returns
a tuple containing that new connection wrapped with a server-side
SSL channel, and the address of the remote client."""
newsock, addr = socket.accept(self)
try:
return (SSLSocket(newsock,
keyfile=self.keyfile,
certfile=self.certfile,
server_side=True,
cert_reqs=self.cert_reqs,
ssl_version=self.ssl_version,
ca_certs=self.ca_certs,
ciphers=self.ciphers,
do_handshake_on_connect=self.do_handshake_on_connect,
suppress_ragged_eofs=self.suppress_ragged_eofs),
addr)
except socket_error as e:
newsock.close()
raise e
示例3: close
# 需要导入模块: from socket import socket [as 别名]
# 或者: from socket.socket import close [as 别名]
def close(self):
if self._makefile_refs < 1:
self._sslobj = None
socket.close(self)
else:
self._makefile_refs -= 1
示例4: makefile
# 需要导入模块: from socket import socket [as 别名]
# 或者: from socket.socket import close [as 别名]
def makefile(self, mode='r', bufsize=-1):
"""Make and return a file-like object that
works with the SSL connection. Just use the code
from the socket module."""
self._makefile_refs += 1
# close=True so as to decrement the reference count when done with
# the file-like object.
return _fileobject(self, mode, bufsize, close=True)
示例5: send_queue
# 需要导入模块: from socket import socket [as 别名]
# 或者: from socket.socket import close [as 别名]
def send_queue(self, udp_socket):
server_list = self.SyslogService.syslog_servers
while self.SyslogService.syslog_queue:
try:
message = self.SyslogService.syslog_queue.popleft()
# sending to all configured server, soft cap of 2
for server, server_info in server_list.items():
server_port = server_info['port']
udp_socket.sendto(message, (server, server_port))
except OSError:
traceback.print_exc()
finally:
udp_socket.close()
示例6: disconnect_socket
# 需要导入模块: from socket import socket [as 别名]
# 或者: from socket.socket import close [as 别名]
def disconnect_socket(self, tcp_connections):
for socket in tcp_connections:
socket.close()