Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 07-27-2005, 03:05 PM   #1
Registered: Nov 2004
Location: Edinburgh, UK
Distribution: Fedora Core 3
Posts: 188

Rep: Reputation: 30
Network Protocol Programming Woes :S..........

I have been following Beej's Networking Tutorial 2.3.1 at ( ). I am currently using his last example on the "Synchronous I/O Multiplexing" selectserver.c but changed it to handle unconnected datagram sockets.

Currently my server just sends a "1" character to the client and the client responds with a double[32][4]. This is working fine. What am interested in is expanding the protocol to include other instructions. However Beej didn't cover any protocol programming. So am wondering if anyone knows any good tutorials on protocol programming. Or even a good protocol library/suite that can be easily used with Beej's selectserver.c.

Below is a protocol idea I have in mind for my application of a Real-Time Linux Cluster Monitor:

Server Commands:
"C" - Retrieve Group Of Hosts Processor Statistics
"M" - Retrieve Group Of Hosts Memory Info
"A" - Retrieve Both Group Of Hosts Processor & Memory
"X" - Shutdown Client Program
"G:1:2:3:4:5" - Change Group Of Hosts To Monitor
(Should I send integers since they're smaller than characters?)

Client Replies:
"C", double[32][4] // User, System, Nice, Idle
"M", double[32][8] // Used, Shared, Buffers, Cache, Swap Used, Load Avg (1min, 5min 15min)
(Is this the best way? Client sends a character then a double array? Or should I packaged them up in a structure? Is it possible to send a structure? Since we're sending 32x8 doubles would compression help lowering the network over-head? Is the character id reply unnessary? Would omitting the character id in the reply be okay?)
"A" struct {double[32][4]; double[32][8];}

Last edited by kevingpo; 07-27-2005 at 03:13 PM.
Old 07-27-2005, 03:25 PM   #2
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 125Reputation: 125
Umm, integers are larger than characters. Now, the string representation of a number may well be larger than an integer version (at values>=10,000).

On another note... be very careful with all this. Passing structs and the like over the network requires that both ends have the structs compiled in EXACTLY the same way. (Same order, same sizes, the works).

Depending on compilation options, some structs may look differently on each end, unless you're careful to use the same compiler version and options. In other words: expand the data manually and then re-read it manually.

Are you going to be running over TCP or UDP? That affects the design of your protocol, of course.

I would not use compression for situations you've described above. Compression does not work well for small amounts of data and has a tendency to use more CPU than its worth. If you're running a cluster, they'll all need to be connected via some sort of decent bandwidth interconnect, so you shouldn't be worried about a ~256 byte message.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Network Time protocol ssg14j Linux - Networking 3 10-26-2005 04:58 PM
Who has experiece in Econet Protocol programming? jamespayne Programming 0 12-13-2004 08:35 AM
Socket Programming: setsockopt: Protocol not available bonhomme Programming 5 06-30-2004 12:52 PM
http protocol/programming advice... Scrag Programming 2 06-20-2004 11:00 PM
KIOSLAVE (Kde Protocol Programming) jinksys Programming 0 03-11-2004 07:07 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:04 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration