Writing the network part of a C program [closed] - c

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have begun writing (in C) a small client/server application which relies on TCP. I lack any experience in network programming. I'm sorry for the open-ended character of this post.
I'm wondering how best to encode and decode messages. I've chosen the following approach:
The client sends commands to the server. Every command has a number assigned to it and a struct. The struct stores the command's arguments and the way the arguments are laid out in memory (and in the stream as well). When the client wants to send a command, it fills the respective struct with data. In order for the server to recognize the command, the client sends one byte which contains the command number. Right after the command number byte, the message itself is fed to the stream (with its fields properly converted to network byte order).
This approach led to working code, but it entails a lot of redundancy (I find myself writing switch statements over and over). Is there a better way? What's the standard procedure?

Google's Protocol Buffers are a nice way to serialize/deserialize data. There are implementations for C.

Related

Make generic program - build execution graph (tree) and execute it in ansi C engine? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm trying to implement PLC like HW that would be able to be programmed with some universal programming language (can be ANSI C for a start).
I'd like to program HW in several steps :
write generic program in txt file (can be subset of ANSI C for a
start)
parse that txt file and build some sort of execution graph to
be sent to ansi c engine on embedded HW
have ansi c engine that can execute "execution graph" over and over...
I've found pretty similar and interesting project here:
http://collaboration.cmc.ec.gc.ca/science/rpn/biblio/ddj/Website/articles/DDJ/1989/8908/8908d/8908d.htm
but this is interpreter and parses program as a text for each step and is getting pretty slow and not space friendly. What I would like to change in this story is to parse C program in execution structure (AST?) once and then just execute it with ansi c engine on embedded HW.
I'm pretty sure that something similar is already done and shared. Please help me with starting points, advice or any other opinion...
Thanks in advance,
regards,
Bulek.

Where can I learn about programming a serial/terminal interface? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have a project I'm going to be doing on a microcontroller. I plan on having it interface with my computer over a USB serial connection. I tried doing the basic tests like putc(getc()), but I'm having trouble getting it to behave as I expect.
With that simple hardware-echo thing, many things just don't work. When I push enter, I just get a carriage return. Backspace does nothing. CTRL-C for breaking doesn't work either.
I'm using GNU Screen as my terminal emulator. How do I learn how to handle all of this(along with stty settings) so I can make a useful command interface on my microcontroller?
You will need to know what terminal type your Screen terminal is emulating so that you know what codes to send out the serial port. For example, if you set your terminal to VT100, you can check out this link which provides some VT100 codes
And for gnu-screen you might want to check this out as it contains an exhaustive list of ESC and control strings/commands that you can use.

2D real-time plot with C [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I've just recently begun programming in C. I currently have an application that read's in values from a COM port and write them to a file. It reads about 500 data points per second. I want to be able to compute a real-time 2D plot of the data points with respect to time. Can someone please point me in the right direction?
I've tried to post-process the data in Excel and the built in capabilities allow me to get a great graph. However, I would just like something that is computed in real-time rather than post processing it. I am using Windows XP.
Thanks in advance !
You can use KST to plot your graphs in real time. You can probably keep your existing application as is (I assume you are writing to a CSV file if you are reading it in Excel) as KST will read the data from the file as it gets updated, and update its chart.
Here are some options for you to explore:
You can use OpenGL and in particular, GLUt. I have some C code for
this if you are interested.
You can pipe commands to gnuplot.
You can use GNU Octave from a C/C++ program. You can read more about
this here.
You can create your own bitmaps in real-time of you graphs. This isn't as hard as it sounds.

Why is there not a wiki on pipes? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
I am reading the C programing guide and all of a sudden it starts talking about pipes. Can someone simply tell me what a pipe is.
They are OS objects appearing as file descriptors in different processes, allowing output of one to be the input of the other. Read here.
You want to read Beej's IPC Guide, specifically the pipe section.
There is no form of IPC that is simpler than pipes. Implemented on every flavor of Unix, pipe() and fork() make up the functionality behind the "|" in "ls | more". They are marginally useful for cool things, but are a good way to learn about basic methods of IPC.
Also check the other guides at http://beej.us/guide/.
Most likely, this means a Pipeline as in the context of Unix-like operating systems, see Pipeline (Unix) in Wikpedia. It is a chain of processes with the output of one process being the input to the next one.

Modifying an open source program? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I would consider myself a fairly competent programmer with experience in Java and VB.net. My latest swim around the programming lake is having me modify a program written in C. (The program is Wireshark, an open source network analyzing tool.) I followed the instructions here http://www.wireshark.org/docs/wsdg_html_chunked/ChSetupWin32.html and simply don't know where to go from there. I'd like to use Visual Studio 2008 to work with the code if possible, but will do whatever is necessary. (I'm a total noob at using command prompt to do anything though.)
If you followed those steps, then you've built it. I'll copy Section 2.2.10 here.
2.2.10. Build Wireshark
Now it's time to build Wireshark ...
If you've closed cmd.exe in the meantime, prepare cmd.exe again
nmake -f Makefile.nmake all to build Wireshark
wait for Wireshark to compile - this may take a while!
run C:\wireshark\wireshark-gtk2\wireshark.exe and check if it starts
Just make changes in the code, do these steps over again, and presto! you've modified the program. You may want to bone up on C debuggers if you're doing anything very complicated.

Resources