May-11-2017, 05:16 PM
(This post was last modified: May-11-2017, 06:14 PM by adithyakrish.)
(May-11-2017, 05:13 PM)nilamo Wrote: Did you try it?I'm about to try it..
Is that your ip, or the ip of a different computer? You can't bind to a port of an ip that isn't your computer, that's not how networks work.
Thats actually the IP of the board that is connected to my system!
I'm echoing data from that board through that port (7)
I need to know whether this program will help me read the data from that port!
(Mar-31-2017, 11:56 AM)wavic Wrote:The code is not working! Lots of syntax errors.. or that's what the compiler suggests!import asyncio import socket host = '0.0.0.0' port = 8888 loop = asyncio.get_event_loop() s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.setblocking(False) s.bind((host, port)) s.listen(10) async def handler(conn): while True: data = await loop.sock_recv(conn, 65535) if not data: break await loop.sock_sendall(conn, data) conn.close() async def server(): while True: conn, addr = await loop.sock_accept(s) loop.create_task(handler(conn)) loop.create_task(server()) loop.run_forever() loop.close()The code is not mine. I've found it in my Python_tutorials folder. I was digging for async/await a lot and still don't know how to use it.