當前位置: 首頁>>代碼示例>>Python>>正文


Python socket.close方法代碼示例

本文整理匯總了Python中socket.close方法的典型用法代碼示例。如果您正苦於以下問題:Python socket.close方法的具體用法?Python socket.close怎麽用?Python socket.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在socket的用法示例。


在下文中一共展示了socket.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的socket.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。