本文整理汇总了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
示例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
示例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()
示例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)
示例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)
示例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)
示例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