| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 | Nanopb example "network_server"===============================This example demonstrates the use of nanopb to communicate over networkconnections. It consists of a server that sends file listings, and ofa client that requests the file list from the server.Example usage-------------user@host:~/nanopb/examples/network_server$ make        # Build the exampleprotoc -ofileproto.pb fileproto.protopython ../../generator/nanopb_generator.py fileproto.pbWriting to fileproto.pb.h and fileproto.pb.ccc -ansi -Wall -Werror -I .. -g -O0 -I../.. -o server server.c    ../../pb_decode.c ../../pb_encode.c fileproto.pb.c common.ccc -ansi -Wall -Werror -I .. -g -O0 -I../.. -o client client.c    ../../pb_decode.c ../../pb_encode.c fileproto.pb.c common.cuser@host:~/nanopb/examples/network_server$ ./server &  # Start the server on background[1] 24462petteri@oddish:~/nanopb/examples/network_server$ ./client /bin  # Request the server to list /binGot connection.Listing directory: /bin1327119    bzdiff1327126    bzless1327147    ps1327178    ntfsmove1327271    mv1327187    mount1327259    false1327266    tempfile1327285    zfgrep1327165    gzexe1327204    nc.openbsd1327260    unameDetails of implementation-------------------------fileproto.proto contains the portable Google Protocol Buffers protocol definition.It could be used as-is to implement a server or a client in any other language, forexample Python or Java.fileproto.options contains the nanopb-specific options for the protocol file. Thissets the amount of space allocated for file names when decoding messages.common.c/h contains functions that allow nanopb to read and write directly fromnetwork socket. This way there is no need to allocate a separate buffer to storethe message.server.c contains the code to open a listening socket, to respond to clients andto list directory contents.client.c contains the code to connect to a server, to send a request and to printthe response message.The code is implemented using the POSIX socket api, but it should be easy enoughto port into any other socket api, such as lwip.
 |