Networking

Hey all!

Trying to send a dummy message from pynq-z2 to host using this protocol:

hostListen.py:

import socket

host = "192.168.2.1"  # FPGA IP
port_ = 9091  # Shared port

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.bind((host, port_))
    s.listen()
    conn, addr = s.accept()
    with conn:
        print(f"Connected by {addr}")
        while True:
            data = conn.recv(1024)
            if not data:
                break
            conn.sendall(data)

z2SendPing.ipynb:

import socket

host = "192.168.2.1"  # The server's hostname or IP address
port_ = 9091  # The port used by the server

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.connect((host, port_))
    s.sendall(b"Hello, world")
    data = s.recv(1024)

print(f"Received {data!r}")

But the ping-er stalls …

Does anyone know what the issue is?

If it helps; this is my connection config on windows:

PS C:\Users\...> ipconfig

Windows IP Configuration


Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::5097:8a00:5ec2:25fe%18
   IPv4 Address. . . . . . . . . . . : 192.168.2.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :

Wireless LAN adapter Local Area Connection* 1:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter Local Area Connection* 10:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Ethernet adapter vEthernet (WSL):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::14cd:fe3c:9991:cfd7%42
   IPv4 Address. . . . . . . . . . . : 172.24.144.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :

And this is the Z2 config:

root@...:/# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::205:6bff:fe02:6ab8  prefixlen 64  scopeid 0x20<link>
        ether 00:05:6b:02:6a:b8  txqueuelen 1000  (Ethernet)
        RX packets 13478  bytes 6199746 (6.1 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 12932  bytes 7722885 (7.7 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 28  base 0xb000  

eth0:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.99  netmask 255.255.255.0  broadcast 192.168.2.255
        ether 00:05:6b:02:6a:b8  txqueuelen 1000  (Ethernet)
        device interrupt 28  base 0xb000  

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 45006  bytes 4340801 (4.3 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 45006  bytes 4340801 (4.3 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Thanks!

Will transfer 100 Algos to your Algorand wallet for whoever points to correct solution :biting_lip:

Hi,

This is not really a PYNQ question. However, you have to consider which system is the server, and which system in the client. Then, you can specify the IP addresses properly.

What is even easier is to bind to any IP in the server, like this one A simple Python echo server, show how to write socket program use python. · GitHub

Mario

Thanks :slight_smile: … I tried:

import socket

HOST = ''                 # Symbolic name meaning all available interfaces
PORT = 50007              # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)

conn, addr = s.accept()
print ('Connected by', addr)
while 1:
  data = conn.recv(1024)
  if not data: break
  conn.sendall(data)
conn.close()
import socket

HOST = ""  # FPGA IP
PORT = 50007  # Shared port

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.connect((HOST, PORT))
    s.sendall(b"Hello, world")
    data = s.recv(1024)

print(f"Received {data!r}")

But it is still not working … same hang on server side, and [111] connection refused on pynq

:frowning:

Where are you running the server? The client has to specify the IP address it wants to connect to.

The server is on the windows machine detailed here, connected by ethernet. It’s the same machine that is plugged into the pynq, via ethernet, directly.