Here's a tutorial
Tarcas wrote:Given your level of network knowledge, my suggestion is to not do raw socket programming. If all you want is for a script to be run on each Pi, there's already a framework for that through SSH. It allows you to run a command on another computer, just by passing it through the SSH program. I know you said you don't want extra overhead, but unless you're working in the nanosecond timescale, this should easily be fast enough. Most people underestimate the raw speed that computers and networks function at, and I think you've done this. What are you trying to accomplish with your instantaneous script executions?
There is no such thing as an (in-spec) Ethernet splitter, and there never has been or will be. Ethernet connections might look like phone connections, but they're fundamentally very different. Hubs were the closest thing to an "Ethernet Splitter" that ever existed, and as Ivan said, they've been replaced by switches. Unless you're looking at used gear from decades ago, it's very hard to find a hub anymore, and there are very few reasons you'd even want one instead of a switch.
I managed to get exactly the kind of set up I'm after using this tutorial:
http://www.binarytides.com/python-socke ... -tutorial/
But I'm interested how one would use SSH. It was my first thought, but after experimenting it seemed to clunky for my purposes (at least the command line interface did).
How do you suggest I set up a local network?
with some examples of how to use SSH to execute a command remotely. Basically it's just "ssh [email protected]
command arguments." There's a link near the bottom of that page to set up public key based authentication so that you don't need to put in your password every time. You'll want that for doing this in an automated fashion, which is clearly what you're doing here.
How to set up a local network depends greatly on how the network will be used. Since you haven't described your project very thoroughly, I'll make some assumptions based on what you have stated, and design a simple network based on those.
1) 4 devices: a server and 3 pis
2) wired connection to each (no wifi)
3) no router, no Internet connectivity, no DHCP, no special IP addressing requirements or restrictions
Step 1 - Get an Ethernet switch and 4 Ethernet cables. Since not much data will be passing, a 10 Mbps switch will probably be fine, but 100 Mbps will be easier to find, not much more expensive, and allow for better future expansion. You could also get a home router with 4 or more switch ports built in (don't count the uplink port - that's not a switch port.) but that will change some of my future steps, so stop here and ask for the alternate design if you choose a router instead.
Step 2 - Connect the cables from each device to the switch. It doesn't matter which port you plug each device into, but keeping them in some order that makes sense to you is wise. Labeling them is also wise if you don't want to have to guess and check when you need to change something in a few months or a few years. As you connect, each set of lights should come on.
Step 3 - Assign static IP addresses and subnet mask to each device. For your setup, use 192.168.0.10 through 192.168.0.14 (only the last octet of the IP changes. It must be unique on each device, and the other 3 must match.) with subnet mask 255.255.255.0. Look up tutorials on setting up a static IP on each device. Google and Youtube will have loads of instructions for this.
Step 4 - Test. From each device, ping the IP addresses of each other device. If any fails, have that device ping itself. If pinging itself fails, that device's IP was set up wrong. If pinging others fails, post the ping results here or google them for interpretation.
Note that this is an EXTREMELY basic network with no functionality besides what you will create for it separately. It can't get to the outside world, and any new device will need another IP assigned in the correct range.
EDIT: Added link to the tutorial
on using SSH to run commands remotely. Apparently I forgot to put it in the first time.