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. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
11-19-2012, 02:45 PM
|
#1
|
|
Member
Registered: Jul 2012
Posts: 106
Rep: 
|
How can I program a Linux server with client a website in gcc C/C++?
I want to program a linux server in C/C++ that will have as client a website (in Java,PhP,etc. the easiest one)
I want to be able to receive string queries from the client-website and reply it back arrays
(Do they have to be converted to HTML arrays or something?)
What do I have to do?
|
|
|
|
11-19-2012, 04:14 PM
|
#2
|
|
Senior Member
Registered: Nov 2007
Location: Somewhere on my hard drive...
Distribution: Arch
Posts: 2,044
|
Nothing, just set up a server, install what you need on that server( Java, PHP, ...) set up some pages and you're set...it's called a ... webserver...
Thor
|
|
|
|
11-19-2012, 04:44 PM
|
#3
|
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,270
|
esgol, your jargonology is completely mixed up. 'as client a website' is completely meaningless. A website is a HTTP server (web server), along with the collection of HTML pages, images, and scripts that are served and launched by the HTTP server. Nothing about a web site is client-like. Given that, your statement 'I want to be able to receive string queries from the client-website' is equally meaningless. A web client is generally a browser, or some browser-like software.
So, I will assume that what you really mean is that you want to create a website, and that the website must provide a way of receiving information from web clients (browsers). If so, then you will need to learn about CGI, as applied to web servers. In summary, it is a method which provides for server-side extensions to be called from the web-server (so, running on the web server host), and which are given data that is passed from the web client/browser. Usually, but not necessarily, the data passed to the CGI process will originate from an HTML form that a browser loads from the server. You may also want to use PHP, which has some similarilty to CGI processes.
There are many details about how a CGI process is created, and there are many many online tutorials and examples to study. If this does not sound like what you are trying to achieve, please rephrase your question, perhaps leaving out any technical terms that you may be using incorrectly and thereby creating confusion.
--- rod.
|
|
|
|
11-19-2012, 05:20 PM
|
#4
|
|
Senior Member
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 3,669
|
Are you saying that you want a web service that returns json?
|
|
|
|
11-20-2012, 12:44 AM
|
#5
|
|
Member
Registered: Jul 2012
Posts: 106
Original Poster
Rep: 
|
EDITL Please allow me to post it in a new topic since the title was rubish.
----------------------
Ahh as i see in a C++ Web Programming Tutorial at tutorialpoints
its different in programming a web server than a simple server (is he called network server?)
The webserver uses CGI libraries
I have created a C/C++ console aplication with gcc (g++) (4.4.5) which is a simple DBMS ( Database Management System )
It takes SQL strings, parses-analyses them, and extracts the data from the DataBase (Random Access Files ) through Functions handling Data Structures, returning the reply as a char Array
The entire thing is set in the Client-Server model with 2 different classes (CLIENT-SYSTEM) communicating only through a structure called socket, though the functions 'send-listen socket'
I want now to create a real server client and was wondering how could I make instead of a simple server a webserver like you sed its called.
So I want to create a website (Php or Java) and the queries-strings that the user sents from my Website, to arrive at my api-DBMS-server -instead of going to MySQL or whatever its used- and my api-DBMS to reply back to the website the Answer table.
So whatdo I have to do? I know only about simple echo servers with UNIX berkley sockets.
Is this about JDBC-ODBC driver programming?
So its a communication between 2 web servers (the DBMS one, and the website) not a server and a client eh..
P.S.
Sorry I dont have knowledge how exactly the dynamic wesites share information with their webservers :SSS
To understand, when you sed CGI the 1st i came up are the CGI effects used movies :SS
Last edited by esgol; 11-20-2012 at 05:26 AM.
|
|
|
|
11-20-2012, 09:59 AM
|
#6
|
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,270
|
CGI = Common Gateway Interface. A HTTP server, such as Apache, runs on a host serving requests from clients (browsers). When the request URL from a browser includes cgi-bin/someProgramThatYouCreate, then the Apache web server will launch your application. Depending on the nature of the HTTP request, your application will receive data that originated on the browser as either commandline data, or as standard input (on Linux). The CGI application that you write will process the data according the the application requirements. It must also, then, compose a valid HTML page, and write it to its standard output, where the Apache web server will pass it along, back to the HTTP browser.
You can, therefore, write your application in any programming language that can read standard input, write standard output, and receive commandline arguments.
PHP applications are done differently. PHP gets built into the web server in a way that allows it to be launched from any URL, and it processes data embedded into pages resident on the server, as well as receiving data from browser clients.
In order for you to start creating a web application, you will need a host capable of running a web server. Most Linux distros include Apache as the default, and it it often set up to run with little or no configuration required. From there, you can start to compose your CGI scripts &/or PHP applications. Use a conventional browser to test, and if you use anything that is not dead-standard HTML, you will probably need to tweak it to work properly on all browsers.
You will need to learn some HTML for sure, and probably some CSS, maybe some Javascript. Java is not usually used as a CGI language due to its characteristically long startup times. Perl is a very common CGI language.
--- rod.
|
|
|
1 members found this post helpful.
|
11-20-2012, 12:54 PM
|
#7
|
|
Member
Registered: Jul 2012
Posts: 106
Original Poster
Rep: 
|
Wooe thank you very much!
So no need to program servers from zero with forks and sockets etc.  wow! Seems so easy
But how can the input you say arrive my api? through int main(char arg) etc.?
|
|
|
|
11-20-2012, 01:57 PM
|
#8
|
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,270
|
As I said before: 'your application will receive data that originated on the browser as either commandline data, or as standard input (on Linux). The CGI application that you write will process the data according the the application requirements. It must also, then, compose a valid HTML page, and write it to its standard output'
HTTP GET requests use the commandline to send arguments (normally key/value pairs) to the CGI application, while HTTP POST reqests use standard input for data passing.
--- rod.
|
|
|
|
11-20-2012, 02:10 PM
|
#9
|
|
Member
Registered: Jul 2012
Posts: 106
Original Poster
Rep: 
|
Ahh yes I know GET POST from PhP. In order to receive from Post my c++ cgi shall have some special argument at int main() like when receiving at startup fro teh command line? How is it done
About sending from teh command line, what re you talking about there is no comand line in a browser.
About the html export, yes of course, like php and java. Browser wants HTML in the end
thank you the most for your help u already giave me
edit: I found some tutorials, like these. Thank they ll help. If i ll need anything else will come back
http://www.cs.tut.fi/~jkorpela/forms/cgic.html
http://www.openroad.org/cgihelp/cgi.html
http://www.purplepixie.org/cgi/howto.php
Thank you very much 
Last edited by esgol; 11-20-2012 at 02:25 PM.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 04:20 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|