Python socket.close方法代码示例

本文整理汇总了Python中socket.close方法的典型用法代码示例。如果您正苦于以下问题:Python socket.close方法的具体用法?Python socket.close怎么用?Python socket.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块socket的用法示例。

在下文中一共展示了socket.close方法的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: stop

# 需要导入模块: import socket [as 别名]
# 或者: from socket import close [as 别名]
def stop(self):
		self._stop = True
		if self.threads:
			for t in self.threads:
				t.stop()
		
		# not so nice solution to get rid of the block of listen()
		# unfortunately close() does not help on the block
		try:
			server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
			serverbind = self.config.get("Global", "serverbind")
			if serverbind == "0.0.0.0":
				# windows does not like to connect to 0.0.0.0
				serverbind = "127.0.0.1"
			server_socket.connect((serverbind, int(self.config.get(self.get_module_configname(), "serverport"))))
		except:
			pass
		return 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:23,代码来源:TCP_generic.py


示例2: stop

# 需要导入模块: import socket [as 别名]
# 或者: from socket import close [as 别名]
def stop(self):
		self._stop = True
		if self.threads:
			for t in self.threads:
				t.stop()
		
		# not so nice solution to get rid of the block of listen()
		# unfortunately close() does not help on the block
		try:
			server_socket = self.sctp.sctpsocket_tcp(socket.AF_INET)
			if self.config.get("Global", "serverbind") == "0.0.0.0":
				server_socket.connect(("127.0.0.1", int(self.config.get(self.get_module_configname(), "serverport"))))
			else:
				server_socket.connect((self.config.get("Global", "serverbind"), int(self.config.get(self.get_module_configname(), "serverport"))))
		except:
			pass
		return 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:21,代码来源:SCTP_generic.py


示例3: sendAPRSPacket

# 需要导入模块: import socket [as 别名]
# 或者: from socket import close [as 别名]
def sendAPRSPacket(socket, packet):
    """
    Sends an APRS packet (just a string) to the socket specified. If an
    error occurs a False is returned while a True is returned if successful.
    On an error, the socket is closed as it is no longer useful.
    :param socket: APRS-IS server internet socket
    :param packet: String to be sent to APRS-IS
    :return: Boolean
    """
    try:
        socket.sendall(packet)
        return True
    except IOError as e:
        logger.error(e)
        socket.close()
        return False 
开发者ID:FaradayRF,项目名称:Faraday-Software,代码行数:21,代码来源:aprs.py


示例4: close

# 需要导入模块: import socket [as 别名]
# 或者: from socket import close [as 别名]
def close(self):
        """Close the socket underlying this connection."""
        self.rfile.close()
        if not self.linger:
            # Python's socket module does NOT call close on the kernel socket
            # when you call socket.close(). We do so manually here because we
            # want this server to send a FIN TCP segment immediately. Note this
            # must be called *before* calling socket.close(), because the latter
            # drops its reference to the kernel socket.
            # Python 3 *probably* fixed this with socket._real_close; hard to tell.
##            self.socket._sock.close()
            self.socket.close()
        else:
            # On the other hand, sometimes we want to hang around for a bit
            # to make sure the client has a chance to read our entire
            # response. Skipping the close() calls here delays the FIN
            # packet until the socket object is garbage-collected later.
            # Someday, perhaps, we'll do the full lingering_close that
            # Apache does, but not today.
            pass 
开发者ID:exiahuang,项目名称:SalesforceXyTools,代码行数:23,代码来源:wsgiserver3.py


示例5: respond

# 需要导入模块: import socket [as 别名]
# 或者: from socket import close [as 别名]
def respond(self):
        """Process the current request."""
        response = self.req.server.wsgi_app(self.env, self.start_response)
        try:
            for chunk in response:
                # "The start_response callable must not actually transmit
                # the response headers. Instead, it must store them for the
                # server or gateway to transmit only after the first
                # iteration of the application return value that yields
                # a NON-EMPTY string, or upon the application's first
                # invocation of the write() callable." (PEP 333)
                if chunk:
                    if isinstance(chunk, unicodestr):
                        chunk = chunk.encode('ISO-8859-1')
                    self.write(chunk)
        finally:
            if hasattr(response, "close"):
                response.close() 
开发者ID:exiahuang,项目名称:SalesforceXyTools,代码行数:20,代码来源:wsgiserver3.py


示例6: close

# 需要导入模块: import socket [as 别名]
# 或者: from socket import close [as 别名]
def close(self):
        """Close the socket underlying this connection."""
        self.rfile.close()
        if not self.linger:
            # Python's socket module does NOT call close on the kernel socket
            # when you call socket.close(). We do so manually here because we
            # want this server to send a FIN TCP segment immediately. Note this
            # must be called *before* calling socket.close(), because the latter
            # drops its reference to the kernel socket.
            if hasattr(self.socket, '_sock'):
                self.socket._sock.close()
            self.socket.close()
        else:
            # On the other hand, sometimes we want to hang around for a bit
            # to make sure the client has a chance to read our entire
            # response. Skipping the close() calls here delays the FIN
            # packet until the socket object is garbage-collected later.
            # Someday, perhaps, we'll do the full lingering_close that
            # Apache does, but not today.
            pass 
开发者ID:exiahuang,项目名称:SalesforceXyTools,代码行数:23,代码来源:wsgiserver2.py


示例7: run

# 需要导入模块: import socket [as 别名]
# 或者: from socket import close [as 别名]
def run(self):
        self.server.stats['Worker Threads'][self.getName()] = self.stats
        try:
            self.ready = True
            while True:
                conn = self.server.requests.get()
                if conn is _SHUTDOWNREQUEST:
                    return
                self.conn = conn
                if self.server.stats['Enabled']:
                    self.start_time = time.time()
                try:
                    conn.communicate()
                finally:
                    conn.close()
                    if self.server.stats['Enabled']:
                        self.requests_seen += self.conn.requests_seen
                        self.bytes_read += self.conn.rfile.bytes_read
                        self.bytes_written += self.conn.wfile.bytes_written
                        self.work_time += time.time() - self.start_time
                        self.start_time = None
                    self.conn = None
        except (KeyboardInterrupt, SystemExit), exc:
            self.server.interrupt = exc 
开发者ID:joxeankoret,项目名称:nightmare,代码行数:27,代码来源:__init__.py


示例8: respond

# 需要导入模块: import socket [as 别名]
# 或者: from socket import close [as 别名]
def respond(self):
        response = self.req.server.wsgi_app(self.env, self.start_response)
        try:
            for chunk in response:
                # "The start_response callable must not actually transmit
                # the response headers. Instead, it must store them for the
                # server or gateway to transmit only after the first
                # iteration of the application return value that yields
                # a NON-EMPTY string, or upon the application's first
                # invocation of the write() callable." (PEP 333)
                if chunk:
                    if isinstance(chunk, unicode):
                        chunk = chunk.encode('ISO-8859-1')
                    self.write(chunk)
        finally:
            if hasattr(response, "close"):
                response.close() 
开发者ID:joxeankoret,项目名称:nightmare,代码行数:19,代码来源:__init__.py


示例9: cleanup

# 需要导入模块: import socket [as 别名]
# 或者: from socket import close [as 别名]
def cleanup(self):
		try:
			self.comms_socket.close()
		except:
			pass
		if self.serverorclient:
			self.packetselector.delete_client(self.client) 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:10,代码来源:TCP_generic.py


示例10: cleanup

# 需要导入模块: import socket [as 别名]
# 或者: from socket import close [as 别名]
def cleanup(self, socket):
		common.internal_print("Shutting down module: {0}".format(self.get_module_name()))
		socket.close()
		return 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:7,代码来源:SCTP_generic.py


示例11: delete_client

# 需要导入模块: import socket [as 别名]
# 或者: from socket import close [as 别名]
def delete_client(self, client):
		if client in self.clients:
			if self.os_type == common.OS_WINDOWS:
				import win32file
				try:
					win32file.CloseHandle(client.get_pipe_r())
					win32file.CloseHandle(client.get_pipe_w())
				except Exception as e:
					common.internal_print("Remove authenticated client: CloseHandle exception: {0}".format(e), -1)
			else:
				try:
					client.get_pipe_r_fd().close()
					client.get_pipe_w_fd().close()
				except Exception as e:
					common.internal_print("Remove authenticated client: os.close exception: {0}".format(e), -1)
			client.call_stopfp()
			self.clients.remove(client)
		return
	# This function should run from the point when the framework was started.
	# It runs as an infinite loop to read the packets off the tunnel.
	# When an IPv4 packet was found that will be selected and checked whether
	# it addresses a client in the client list. If a client was found, then the
	# packet will be written on that pipe. 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:30,代码来源:packetselector.py


示例12: shutdown_request

# 需要导入模块: import socket [as 别名]
# 或者: from socket import close [as 别名]
def shutdown_request(self, request):
        """Called to shutdown and close an individual request."""
        self.close_request(request) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:5,代码来源:socketserver.py


示例13: server_close

# 需要导入模块: import socket [as 别名]
# 或者: from socket import close [as 别名]
def server_close(self):
        """Called to clean-up the server.
        May be overridden.
        """
        self.socket.close() 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:9,代码来源:socketserver.py


示例14: close_request

# 需要导入模块: import socket [as 别名]
# 或者: from socket import close [as 别名]
def close_request(self, request):
        """Called to clean up an individual request."""
        request.close() 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:5,代码来源:socketserver.py


示例15: tearDown

# 需要导入模块: import socket [as 别名]
# 或者: from socket import close [as 别名]
def tearDown(self):
        self.resolver.close()
        super(ThreadedResolverTest, self).tearDown() 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:5,代码来源:netutil_test.py


示例16: test_same_port_allocation

# 需要导入模块: import socket [as 别名]
# 或者: from socket import close [as 别名]
def test_same_port_allocation(self):
        if 'TRAVIS' in os.environ:
            self.skipTest("dual-stack servers often have port conflicts on travis")
        sockets = bind_sockets(None, 'localhost')
        try:
            port = sockets[0].getsockname()[1]
            self.assertTrue(all(s.getsockname()[1] == port
                                for s in sockets[1:]))
        finally:
            for sock in sockets:
                sock.close() 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:13,代码来源:netutil_test.py


示例17: test_reuse_port

# 需要导入模块: import socket [as 别名]
# 或者: from socket import close [as 别名]
def test_reuse_port(self):
        socket, port = bind_unused_port(reuse_port=True)
        try:
            sockets = bind_sockets(port, 'localhost', reuse_port=True)
            self.assertTrue(all(s.getsockname()[1] == port for s in sockets))
        finally:
            socket.close()
            for sock in sockets:
                sock.close() 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:11,代码来源:netutil_test.py



注:本文中的socket.close方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。