本文整理匯總了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()