Python Forum
asyncio byte data transfer
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
asyncio byte data transfer
#1
I found the below code from my search on the web. The code provides a sample for server implementation using asyncio

import asyncio
async def handle_echo(reader, writer):
    data = await reader.read(100)
    message = data.decode()
    addr = writer.get_extra_info('peername')
    print("Received %r from %r" % (message, addr))
 
    print("Send: %r" % message)
    writer.write(data)
    await writer.drain()
 
    print("Close the client socket")
    writer.close()
 
loop = asyncio.get_event_loop()
coro = asyncio.start_server(handle_echo, 
                            '127.0.0.1', 
                            8888, 
                            loop=loop)
server = loop.run_until_complete(coro)
print('Serving on {}'.format(server.sockets[0].getsockname()))
loop.run_forever()]



Server echoes the data back to the client, but writers.write transmits the data as string. i have a client program written in C that accepts only data format in bytes. How can I change the above program to tansmit bytes instead of string
likes this post
Reply


Messages In This Thread
asyncio byte data transfer - by gary - Nov-05-2022, 03:01 PM
RE: asyncio byte data transfer - by Gribouillis - Nov-05-2022, 08:44 PM
RE: asyncio byte data transfer - by gary - Nov-06-2022, 04:35 AM
RE: asyncio byte data transfer - by Gribouillis - Nov-06-2022, 09:46 AM
RE: asyncio byte data transfer - by gary - Nov-08-2022, 09:00 AM
RE: asyncio byte data transfer - by Skaperen - Nov-18-2022, 02:45 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python:How to read a recived message that idinfies the client Byte by Byte using UDP learn 2 6,131 Dec-01-2017, 09:47 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020