Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Network Programming
#1
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. Sad
I'm open to all suggestions.
Please help  Sad

Moderator zivoni: moved to more appropriate forum
Reply
#2
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.
Reply
#3
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  Sad
Reply
#4
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()
Reply
#5
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
Reply
#6
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
OS network software. Then it looks like just another drive.

Otherwise sockets can be used

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.
Reply
#7
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.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#8
(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??
Reply
#9
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.
Reply
#10
(May-11-2017, 05:03 PM)nilamo Wrote: 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.

Nooo.. I want it to read at a specific IP!
192.168.1.10 and port 7..

Will it work if I change them?
Reply


Forum Jump:

User Panel Messages

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