matanc1
matanc1

Reputation: 7023

Routing messages through a server in python

I want to implement the following but I'm not sure where to start / what to Google. I'd appreciate some direction since I've never written any program that requires network connectivity and am pretty lost:

I've got 3 Raspberry Pis sitting around. I want 2 of them to be able to chat while the 3rd routes the messages (acts as a server between them).

The general flow of events should be something like this:

  1. Server starts running on Pi #1
  2. Pi #2 starts running and connects to the server (who's IP will be static I guess) with a name he chooses. Pi #3 does the same as #2.
  3. Pi #3 can then, knowing the name of Pi #2, send a message to Pi #2 using: : .

This is the general outline of what I want to achieve.

I'm not sure what the server that runs on Pi #1 should be (I've heard of webserver frameworks like Flask but I don't have enough knowledge to determine if they fit my needs).

I'm also not sure on what I should be using for the client side (Pi #2,3). I could probably use sockets but I assume there is a better / easier way.

Upvotes: 1

Views: 215

Answers (1)

Dietrich
Dietrich

Reputation: 5531

If you are on a private network, XML-RPC might be a good choice, because

  • It's built into Python, see this example
  • You can call remote functions almost as if they where local

Drawbacks:

  • Little network security
  • When sending raw data, it needs to be encoded (since to is a text protocol)

To check if your remote server is running, you can use sockets as in this example.

Upvotes: 2

Related Questions