Bind with Ethernet Port Only

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
samajkapoor
Posts: 2
Joined: Mon Sep 28, 2020 6:16 pm

Bind with Ethernet Port Only

Post by samajkapoor » Tue Sep 29, 2020 7:54 am

In my project I have both a Wifi Connection and an Ethernet Connection. Is it possible to bind the webserver only to the ethernet interface? Currently I can make requests on both the WiFi and the Ethernet Interface.

User avatar
MostlyHarmless
Posts: 163
Joined: Thu Nov 21, 2019 6:25 pm
Location: Pennsylvania, USA

Re: Bind with Ethernet Port Only

Post by MostlyHarmless » Fri Oct 30, 2020 3:58 am

The usocket module perfectly supports bind((<IP>, <PORT>)). When using '0.0.0.0' (AKA INADDR_ANY) for IP, the server socket will accept connections on all active interfaces. To limit it to one specific interface you should obtain that IP address via WLAN.ifconfig() and use it in the bind() call.

You haven't told us which webserver you are using. For picoweb you would specify that address in the run() call for the app.


Hope this helps, Jan

Post Reply