-2

I want to implement a P2P protocol in C for personal education purposes. What would be the protocol with the shortest specification that is still used today?

I have already implemented a web and IRC client and server.

2 Answers2

0

Serial. The answer is serial. You're not going to get any leaner than simple RX/TX communication but you'll lack a lot of convenience methods. If you want to explore more than simple bidirectional comms, I2C or modbus open up a lot of options.

Mark Brown
  • 914
  • 1
  • 11
  • 26
0

I agree with Mark, that point to point over a serial link would be a good exercise.

In particular, I would recommend the following programme of stuff...

  1. Implement basic transmission over a "Serial Port" (using RS-232 if you have some Arduinos/embedded processors lying around, or using a null modem emulator if you don't (see com0com on Windows, or this on linux/mac).

    • I.e. send lower case letters from A->B, and echo them back as upper case from B->A
  2. Implement SLIP as a way to reliably frame messages

    • i.e. you can send any string (e.g. "hello") and it is returned in upper case with "WORLD" appended ("HELLOWORLD").
  3. Implement the "Read Multiple Holding Registers" and "Write Multiple Holding Registers" part of the Modbus protocol, using SLIP to frame the messages.

    • I.e. you have one follower (slave) device, and one leader (master) device. The follower has 10 bytes of memory that are exposed over modbus with the initial value "helloworld".
    • Just hard-code the follower / leader device Ids for now.
    • The leader reads the value, and then sets it to be "worldhello".

At the end of this you would start to have an understanding of the roles of network layers, ie:

  • The physical layer - Serial/RS-232
  • A "link layer" of sorts - SLIP
  • An "application" layer - Modbus
Doddie
  • 1,393
  • 13
  • 21