Python socket.getpeername方法代码示例

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

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

示例1: _connect_one

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getpeername [as 别名]
def _connect_one(self, host, port):
        """Connect to the proxy and perform a handshake requesting a
        connection to (host, port).
        Return the open socket on success, or the exception on failure.
        """
        client = self.protocol(host, port, self.auth)
        sock = socket.socket()
        loop = asyncio.get_event_loop()
        try:
            # A non-blocking socket is required by loop socket methods
            sock.setblocking(False)
            await loop.sock_connect(sock, self.address)
            await self._handshake(client, sock, loop)
            self.peername = sock.getpeername()
            return sock
        except Exception as e:
            # Don't close - see https://github.com/kyuupichan/aiorpcX/issues/8
            if sys.platform.startswith('linux') or sys.platform == "darwin":
                sock.close()
            return e 
开发者ID:lbryio,项目名称:torba,代码行数:23,代码来源:socks.py


示例2: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getpeername [as 别名]
def __init__(self, address, protocol, auth):
        """A SOCKS proxy at an address following a SOCKS protocol.  auth is an
        authentication method to use when connecting, or None.
        address is a (host, port) pair; for IPv6 it can instead be a
        (host, port, flowinfo, scopeid) 4-tuple.
        """
        self.address = address
        self.protocol = protocol
        self.auth = auth
        # Set on each successful connection via the proxy to the
        # result of socket.getpeername()
        self.peername = None 
开发者ID:lbryio,项目名称:torba,代码行数:15,代码来源:socks.py


示例3: get_client_addr

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getpeername [as 别名]
def get_client_addr(self):
        return super(IndexHandler, self).get_client_addr() or self.request.\
                connection.stream.socket.getpeername() 
开发者ID:hequan2017,项目名称:chain,代码行数:5,代码来源:main.py


示例4: sendAck

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getpeername [as 别名]
def sendAck(socket):
    #print("sending ack to "+str(socket.getpeername()))
    ack = FSNObjects.ServerEvent(FSNObjects.ServerEvent.ACK)
    send(ack,socket) 
开发者ID:skyfpv,项目名称:FlowState,代码行数:6,代码来源:server.py


示例5: send

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getpeername [as 别名]
def send(message, socket):
    #print("send()")
    #global outboundMessages
    #outboundMessages.append({"data":message,"socket":socket})
    try:
        dataOut = str(message).encode("utf-8")+delim
        #print("sending message to client: "+str(socket.getpeername()[0])+": "+str(dataOut))
        socket.send(dataOut)
    except Exception as e:
        print(traceback.format_exc())
        socket.close()
        # if the link is broken, we remove the client
        #remove(socket) 
开发者ID:skyfpv,项目名称:FlowState,代码行数:16,代码来源:server.py


示例6: connectionSuccess

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getpeername [as 别名]
def connectionSuccess(self):
        socket = self.sub.socket
        self.sub.state = "dead"
        del self.sub
        self.state = "connected"
        self.cancelTimeout()
        p = self.factory.buildProtocol(self.buildAddress(socket.getpeername()))
        self.transport = self.transport_class(socket, p, self)
        p.makeConnection(self.transport) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:11,代码来源:client.py


示例7: handle_tcp_http

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getpeername [as 别名]
def handle_tcp_http(socket, dstport):
	socket = TextChannel(socket)
	try:
		keep_alive = True
		while keep_alive:
			firstline = readline(socket).strip()
			rematch = re.match("([A-Z]+) ([^ ]+) ?.*", firstline)
			if not rematch:
				raise Exception('Unexpected request')
			verb = rematch.group(1)
			url = rematch.group(2)
			# Skip headers
			keep_alive = False
			user_agent = ''
			while True:
				header = readline(socket).strip()
				if header == '':
					break
				elif header.upper() == 'CONNECTION: KEEP-ALIVE':
					keep_alive = True
				elif header.upper().startswith('USER-AGENT: '):
					user_agent = header[len('USER-AGENT: '):]
			session_token = uuid.uuid4().hex
			log_append('tcp_http_requests', socket.getpeername()[0], dstport, verb, url, user_agent, session_token)
			socket.send("HTTP/1.0 200 OK\nServer: microhttpd (MontaVista/2.4, i386-uClibc)\nSet-Cookie: sessionToken={}; Expires={}\nContent-Type: text/html\nContent-Length: 38\nConnection: {}\n\nmicrohttpd on Linux 2.4, it works!\n\n".format(session_token, __getexpdate(5 * 365 * 24 * 60 * 60), "keep-alive" if keep_alive else "close"))
	except ssl.SSLError as err:
		print("SSL error: {}".format(err.reason))
		pass
	except Exception as err:
		#print(traceback.format_exc())
		pass
	try:
		print("-- HTTP TRANSPORT CLOSED --")
		socket.close()
	except:
		pass 
开发者ID:fabio-d,项目名称:honeypot,代码行数:45,代码来源:tcp_http_https.py



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