0

I run the same Python program on Raspberry and Windows laptop to listen to a blood pressure device over peer2peer UTP cable (no router).

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 281))  # sudo required but provided
s.listen(5)
conn, addr = s.accept()

The program works on laptop, the same program copied to Raspberry Pi 3B+ does not work: no exceptions, but no accepted incoming connection either.

-- context:

I use superuser rights (sudo), Python 3.7.3.

Raspberry has both a WiFi and wired connection (where it listens to different ports)

I can ping the device (using -I eth0) so the network connection should be there.

I did not install a firewall - checked and it is disabled.

Questions:

  1. what am I doing wrong?

  2. can I somehow specify that the socket should be over cable/eth0/wifi/wlan0?

-- edit:

I think it is related to IP traffic: I think my socket listens to wlan0 but traffic is expected via eth0.

Responses must also be returned via eth0.

How could I easily check this/configure this?

  • What is the output of netstat -anp | grep :281 and ifconfig | grep 'inet ' while the python is running. – rtaft Aug 28 at 15:58
  • sudo ip addr , check what is your ip addr for eth0 or wlan0, modify your server for listen only on specific interface IPv4 addr. Check the route with sudo ip route (default gateway). For interface priority see the metric configuration. – Ephemeral Aug 28 at 16:00
  • @Ephemeral probably, just starting with the basics, network working, port is open correctly, no firewall blocking it, etc. – rtaft Aug 28 at 16:29
  • For metric see here. When you use ip addr command, if you have an ip addr for specific interface (ex:192.168.1.1/24), yes it's the server IP addr, then all the hosts on the same network can access to your server for this interface. Also, add print("Connection from:", addr ) in the end of your server code. (Maybe you have missing one line when your are moved the script ?) – Ephemeral Aug 28 at 16:30
  • @rtaft, yes I have deleted my comment because your step is a starting point, you are right – Ephemeral Aug 28 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.