README.txt 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. Nanopb example "network_server"
  2. ===============================
  3. This example demonstrates the use of nanopb to communicate over network
  4. connections. It consists of a server that sends file listings, and of
  5. a client that requests the file list from the server.
  6. Example usage
  7. -------------
  8. user@host:~/nanopb/examples/network_server$ make # Build the example
  9. protoc -ofileproto.pb fileproto.proto
  10. python ../../generator/nanopb_generator.py fileproto.pb
  11. Writing to fileproto.pb.h and fileproto.pb.c
  12. cc -ansi -Wall -Werror -I .. -g -O0 -I../.. -o server server.c
  13. ../../pb_decode.c ../../pb_encode.c fileproto.pb.c common.c
  14. cc -ansi -Wall -Werror -I .. -g -O0 -I../.. -o client client.c
  15. ../../pb_decode.c ../../pb_encode.c fileproto.pb.c common.c
  16. user@host:~/nanopb/examples/network_server$ ./server & # Start the server on background
  17. [1] 24462
  18. petteri@oddish:~/nanopb/examples/network_server$ ./client /bin # Request the server to list /bin
  19. Got connection.
  20. Listing directory: /bin
  21. 1327119 bzdiff
  22. 1327126 bzless
  23. 1327147 ps
  24. 1327178 ntfsmove
  25. 1327271 mv
  26. 1327187 mount
  27. 1327259 false
  28. 1327266 tempfile
  29. 1327285 zfgrep
  30. 1327165 gzexe
  31. 1327204 nc.openbsd
  32. 1327260 uname
  33. Details of implementation
  34. -------------------------
  35. fileproto.proto contains the portable Google Protocol Buffers protocol definition.
  36. It could be used as-is to implement a server or a client in any other language, for
  37. example Python or Java.
  38. fileproto.options contains the nanopb-specific options for the protocol file. This
  39. sets the amount of space allocated for file names when decoding messages.
  40. common.c/h contains functions that allow nanopb to read and write directly from
  41. network socket. This way there is no need to allocate a separate buffer to store
  42. the message.
  43. server.c contains the code to open a listening socket, to respond to clients and
  44. to list directory contents.
  45. client.c contains the code to connect to a server, to send a request and to print
  46. the response message.
  47. The code is implemented using the POSIX socket api, but it should be easy enough
  48. to port into any other socket api, such as lwip.