Search code examples
csocketstcpembeddedlwip

LwIP implementation


I'm implementing a TCP client for an embedded system (Zybo) which has no OS and I'm totally newbie in LwIP. After having googled for a while, I've found few samples of how to use it.

I was wondering if there is any way of sending C structs through it and if there is any sample available. The server is implemented on another Zybo board under Linux and it handles many structures to control the state machine, so it's quite crucial.

Thanks in advance.


Solution

  • LwIP has a TCP stack implementation, so it is capable of (almost?) everything a regular TCP stack can do.

    And of course, it allows you to send arbitrary data over the socket. Neither standard stack, neither LwIP has any specific support for serialization (what you probably want).

    You will need to define a protocol for seraliazing your struct into array of characters, send this array, receive it on the other side and deserialize it. One way of seralizing a structure is so-called entity-serialization - simply send a raw memory footprint of the struct and receive it on the other side. This is very simple, very fast, but very unreliable way of doing it - what if memory layout of the same struct is different between sender and receiver? It also becomes hard to add new fields to the struct as your program evolves (you will always have to add them in the end), and almost impossible to remove a field.

    A better way is to really understand various serialization approaches and figure one which suits you best.