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