Network Programming - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Network Programming (/thread-2638.html) Pages:
1
2
|
Network Programming - adithyakrish - Mar-30-2017 Hello All, I would like to start of by saying that I am new to Python. I have a Zynq board connected to my system and I would like to transmit and receive messages (echo) between my computer and board using Python Network Program. I don't know how to proceed on this issue as I tried a few and nothing has yielded me any results. I tried the loop back program and it is working(the "127.0.0.1" program), but this, i am not sure. I'm open to all suggestions. Please help Moderator zivoni: moved to more appropriate forum
RE: Network Programming - nilamo - Mar-30-2017 What's a zynq board? Is it similar to raspberry pi or arduino? Do you have a link to the actual board you have? Without knowing what it's capable of, we'd be taking guesses as to how to help. That said, how is it connected to the system? If you just want to communicate with the computer you're already plugged in to, there might be easier ways than networking. RE: Network Programming - adithyakrish - Mar-30-2017 Forget all that. My Board is connected to the System. It's IP address is "192.168.1.10" and port number 7. I know this because thats how I echoed the data from the system to the board using telnet. What I want to do is, read that port using Python so that instead of just echoing, I want to read the data using the python program as well. Please help me with this RE: Network Programming - nilamo - Mar-30-2017 Cool. Have you tried sockets? https://docs.python.org/3.6/library/socket.html Something like: import socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(("192.168.1.10", 7)) listening = True while listening: data = sock.recv(1024) if data: print(data) else: listening = False sock.close() RE: Network Programming - Larz60+ - Mar-30-2017 If it's just an Ethernet connection, you should be able to hook it up through your OS network software. Then it looks like just another drive. Otherwise sockets can be used RE: Network Programming - adithyakrish - Mar-31-2017 Hey, Thank you so much for your reply. I tried the program. The program contains no errors, unlike my previous programs. But it does not display the result at all. As in, its either not listening, or its not displaying :/ Please help :( Truly yours, Adithya Krish (Mar-30-2017, 05:44 PM)Larz60+ Wrote: If it's just an Ethernet connection, you should be able to hook it up through your Oh. But mine should be in python using the Sockets. Can you tell me how to "hook" it through OS Network software? That could be helpful as well. RE: Network Programming - wavic - Mar-31-2017 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. RE: Network Programming - adithyakrish - May-11-2017 (Mar-31-2017, 11:56 AM)wavic Wrote: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. Will this work to read data that is being transferred through the Ethernet Cable?? RE: Network Programming - nilamo - May-11-2017 If that data is being passed on port 8888, sure. It's not going to get data on any other port. But that's probably fine, you wouldn't want to consume all ports anyway. RE: Network Programming - adithyakrish - May-11-2017 (May-11-2017, 05:03 PM)nilamo Wrote: If that data is being passed on port 8888, sure. Nooo.. I want it to read at a specific IP! 192.168.1.10 and port 7.. Will it work if I change them? |