from aiohttp import web
import socketio
from aioconsole import ainput
sio = socketio.AsyncServer()
app = web.Application()
sio.attach(app)
@sio.event
def connect(sid, environ):
print("connect ", sid)
@sio.event
def disconnect(sid):
print('disconnect ', sid)
async def chat_message():
while True:
text = await ainput(">>>")
if text == 'exit':
break
else:
await sio.emit("test", text)
sio.start_background_task(chat_message)
if __name__ == '__main__':
web.run_app(app)
import asyncio
import socketio
sio = socketio.AsyncClient()
@sio.event
async def connect():
print('connection established')
@sio.event
def test(data):
print('message received with ', data)
@sio.event
async def disconnect():
print('disconnected from server')
async def main():
await sio.connect('http://localhost:8080')
await sio.wait()
if __name__ == '__main__':
asyncio.run(main())
DATABASE_URL = os.environ['DATABASE_URL']
connection = psycopg2.connect(DATABASE_URL, sslmode='require')
connection = psycopg2.connect(
database='dfgdfgdfgdfg',
user='fdgdgfdg',
password='12345',
host='localhost',
port='5432',
)