I'm sort of new to C language. I came from higher level languages like python and C#. I need to write a small light weight HTTP client for windows which has two features: the first it's that it could eventually perform GET requests, read the content of the page (excluding the headers) and print the results.The second one is to POST the time of the current machine to the server.
In my journey to complete this, I got really confused and currently I have really no idea how to do that.
I'd appreciate your help :)
Thanks !
Check out Beej's Guide to Network Programming, it is a nice guide for beginners in socket programming in C. If you are not a beginner you can just jump to the Client-Server section. There you can find examples on how to build clients and servers in C.
Related
First of all, I have no experience in working with ONVIF at all. I got myself a scholarship at a company and was asked to work with it (to control some cameras and get photos from them), but they don't know how it works either, so no-one can help me much...
I was reading through the specifications available at the ONVIF webpage but I don't really get it. I know I have to use SOAP, C (I was asked to do the app in C), XML and web services. That much I understand but I don't know how am I supposed to use them. I'm not here so that you can do the work for me (that ain't fun) I just would like to know if someone here could guide me a little about what to start learning and in which order. If there's something I forgot to explain I'll add it as soon as I can.
So, you have to start with gSOAP.
Pelco has a guide to get started with gSOAP, it is for windows but it is valid for Linux as well. As you start learning gSOAP, check the last FAQ of gSOAP about the namespaces.
Finally, on the ONVIF website there's an Application Programmers Guide, which is old but still interesting. ONVIF has a forum for all people willing to learn the protocol. It does not require you to be member to access it, you can join it for free and check all the questions there.
A good approach is to study existing code from open source projects. A few of them can be found from an ONVIF challenge top 10 list. Also from the top 7 ONVIF open source projects. Especially it looks the following ones should be a good starting points:
An ONVIF Service Server - onvif_srvd which runs on a linux machine so that your RTSP cameras will be discoverable by other ONVIF tools or clients.
An ONVIF server for PI that turns a webcam into an IP Camera.
An ONVIF client with GUI built-in.
Alrighty so, I've been wanting to learn C for awhile, and now I have a project idea that's actually relevant to a website I want to build, but I have a few initial questions on how to get started. This isn't really a "how to program" question or anything, I can get started with C programming fine, I know how to read and communicate with various APIs and protocols as long as I have documentation, etc. I'm just looking for a starting point, I guess.
The program would be something similar to ice or shoutcast, so basically audio streaming. Does anyone think they could give a brief, high-level overview of what would be required? As I said the end product would be a url you pop in a .pls file and you can stream it to w/e client you want. What protocols, libraries, and documentation should I be looking at?
If you want this to be a toy for learning, you might want to do all the work yourself; it's a complicated problem, and getting it right is definitely going to be educational. A copy of Advanced Programming the Unix Environment, 2nd edition or TCP/IP Illustrated, Vol 1 would be helpful but not strictly necessary.
If you want this to be useful too, I'd suggest starting with libev or libevent. libevent has some built-in HTTP handling, which might be nice, but there are reports that libevents HTTP handling isn't perfect. libev doesn't provide built-in HTTP handling, but it should be easier to write with libev than performing all the work by hand. Using these pre-written event-based libraries will improve the stability and reliability of your program compared to writing the entire thing by hand, though they aren't doing anything that you can't do yourself.
I am interested in making a simple HTTP server in C to play with (of course I'm only expecting to learn more about how a server works and gain some knowledge from there). I saw some topics regarding the same question as well as providing code but that didnt help. Are there any books for what I'm looking for?
First, there are many HTTP server C code out there. At least, have a look into some of them.
There are also several libraries for adding HTTP server abilities to your software. I do like the onion library, but there are others (libmicrohttpd, Wt for C++, etc...).
You need to be fluent with
advanced unix programming
unix networking programming
HTTP protocol
The C10K problem
FastCGI perhaps
I'm not sure it is worth the effort to re-implement a simple HTTP server. You probably won't do better than existing stuff in a reasonable time.
You might learn more by studying and improving existing code.
At last, your question is perhaps off-topic here. Did you consider asking on programmers's forum?
Actually, since HTTP is a complex protocol (above TCP/IP which is itself complex, implemented e.g. on operating systems like Posix or Linux which are complex), you won't be able to make a simple but standard compliant implementation (if you want it robust enough, which is required by HTTP specs). It has to be complex!
You definitely will learn a lot by implementing something simple. Just read a little bit about HTTP (e.g. wikipedia's page on HTTP, and start implementing some simple GET and HEAD requests); but you should have some knowledge about e.g. basic Linux network programming. However, you'll then implement only a subset of HTTP.
I was just reading the http://www.meebo.com/ About Us page, and read this line :
"plus, we're one of the few still around using C!"
Considering that meebo is an online chat client, how do they work with C? How can they use C for the backend? How does it interact with the frontend? For example, let's say a user creates a new account, and new directory is to be made, how does the information go from the front end to the back end?
I'm sorry if it's an invalid question.
Thank you
Edit 1: The Intro Tutorial to CGI was great. Any good books I can pick up from my library regarding this?
Thanks a lot for the quick response guys!
I don't know how meebo does it, but given that it's chat software they probably have a custom server written in C to handle the actual message traffic.
However, Apache and most other HTTP servers have always been able to call C programs just as they can call PHP, CGI and other languages for certain requests. Some websites are even written in Lisp.
The backend has to be compiled each time, unlike an interpreted language, but that happens at rollout and is part of the build/production scripts.
The permissions given and user account that the C program runs under must be carefully chosen, and of course a C website suffers from the same issues any other C program can fall for, such as buffer overrun, segfault, stackoverflow, etc. As long as you run it with reduced permissions you are better protected, and it's no worse than any other language/platform/architecture.
For servers, however, it's still used widely - the gold standard, I suppose. You can find plenty of servers written in Java, C++, and every other language, but C just seems to stick around.
-Adam
I've rolled non-blocking HTTP 1.1 servers in as little as 50 lines of code (sparse) or a few hundred (better), up to about 5k (safe). The servers would load dynamic shared objects as modules to handle specific kinds of requests.
The parent code would handle connection tracking, keep alives, GET/POST/HEAD requests and feed them off to handlers that were loaded on start up. I did this when I was working with VERY little elbow room on embedded devices that had to have some kind of web based control panel .. specifically a device that controlled power outlets.
The entry point to each DSO was defined by the URL and method used (i.e. /foo behaved differently depending on the type of request it was serving).
My little server did quite well, could handle about 150 clients without forks or threads and even had a nice little template system so the UI folks could modify pages without needing hand-holding.
I would most decidedly not use this kind of setup on any kind of production site, even your basic hello world home page with a guest book.
Now, if all I have to do is listen on port 80/443, accept requests with a small POST payload, sanitize them and forward them along to other clients ... its a little different.But that's a task specific server that pretends to be a web server, its not using C to generate dynamic pages.
Meebo uses a custom Lighttpd module called mod_meebo. It doesn't fully answer your question, but I thought you might be interested.
A lot of server-side programs can be done in C, not to mention CGI programming. They could also be Using C with MySQL, which is very possible. But without access to their source code, we have no way of knowing just how much C they are using.
Claiming that they are "one of the few around still using C" was probably just a joke. With stats like this at least I would hope so.
-John
You can see a good example of a web site in C with source code: fossil.
It uses SQLite for the back end.
I'm looking to make my CGI forum software FastCGI compatible.
The forum software consists of a few dlls and .exe (.cgi) files written in C and x86 assembly language. I also have a SQlite3 database.
Lighttpd runs all these cgi scripts as child processes and I much say that the whole thing works pretty damn well.
But I want to experiment with FastCGI. However, the examples are poor, the documentation is poor, and it really looks like it's made for Linux in mind. Did someone get FastCGI working on Windows? If someone has a code example around, and the lighttpd configuration lines, I would be really grateful.
i've done some work with fastcgi on windows. bottom line is its not a lot of fun - you are 100% correct that there aren't a lot of sample and it the documentation is poor. but, the developer who i was helping on this was in contact with the guys who write iis and the fastcgi spec and was able to get his software to work. some changes are in the works to help. here is a link to some information:
http://blogs.iis.net/ksingla/archive/2009/04/20/fastcgi-isapi-1-5-beta-for-winxp-and-win2k3.aspx
i should add that the guy i was working with had so many problems with libfcgi.dll that he ended up rewriting it (see the reference to libfcgi2.dll in the article linked above.)
best regards,
don