我正在制作停车场系统,我在想的是一秒钟内发出的请求数量。我应该使用self.connection_ip
还是应该在定义中执行connection_ip。我当时正在考虑做这堂课来建立联系,但没有成功。
# connection between server and client.
class Connection:
def __init__(self):
self.connection = False
self.new_connection = False
self.connection_time = datetime.datetime.now().strftime('%H:%M %d/%m/%y')
self.connection_ip = None
self.server_ip = Ipv4_Address
#Connect = Connection()
async def connected(request):
connection_ip = request.query['connection_ip']
connection_time = datetime.datetime.now().strftime('%H:%M %d/%m/%y')
server_ip = Ipv4_Address
print(f'{connection_ip} has connected')
request_obj = {
'status' : '200',
'message' : 'Connected',
'ip_ofc' : f'{connection_ip}',
'server_ip' : f'{server_ip}',
'connection_time' : f'{connection_time}'
}
return web.Response(text=json.dumps(request_obj), status = 200)
#=================================== SERVER LAUNCH & CONFIGURATION =================
app = web.Application()
app.router.add_post('/connect',connected)
#app.router.add_post('/regveh', newveh)
#app.router.add_post('/login', login)
#app.router.add_post('/', handle)
#app.router.add_post('/oz', oz)
web.run_app(app)
连接的定义中的所有代码都在名为NewConnection对象的Connection类中。