0
response = {
'error': 'invalid request',
'status': 'retry'
}

synchronous side:

conn.send('HTTP/1.1 200 OK\n')
conn.send('Content-Type: application/json\n')
conn.send('Connection: close\n\n')
conn.sendall(ujson.dumps(response ))

asyncio side:

swriter.write(ujson.dumps(response ))
await swriter.drain()

Client was to able to read json response in synchronous way but reading failed in asyncio, Where is the error?

  • Does this answer your question? [asyncio stream vs synchronous stream in socket communication with a react native app](https://stackoverflow.com/questions/69163368/asyncio-stream-vs-synchronous-stream-in-socket-communication-with-a-react-native) – Lixas Sep 20 '21 at 08:52

1 Answers1

1

got the error: asyncio.wait_for(sreader.readline(), self.timeout)------> changed to

asyncio.wait_for(sreader.read(2048), self.timeout). Now client is recieving json output immediately after closing the socket. Just a timing issue