LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 11-19-2012, 02:45 PM   #1
esgol
Member
 
Registered: Jul 2012
Posts: 106
Blog Entries: 1

Rep: Reputation: Disabled
Question 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?
 
Old 11-19-2012, 04:14 PM   #2
Thor_2.0
Senior Member
 
Registered: Nov 2007
Location: Somewhere on my hard drive...
Distribution: Manjaro
Posts: 2,192
Blog Entries: 23

Rep: Reputation: 278Reputation: 278Reputation: 278
Quote:
What do I have to do?
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
 
Old 11-19-2012, 04:44 PM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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.
 
Old 11-19-2012, 05:20 PM   #4
dugan
Senior Member
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 4,566

Rep: Reputation: 1394Reputation: 1394Reputation: 1394Reputation: 1394Reputation: 1394Reputation: 1394Reputation: 1394Reputation: 1394Reputation: 1394Reputation: 1394
Are you saying that you want a web service that returns json?
 
Old 11-20-2012, 12:44 AM   #5
esgol
Member
 
Registered: Jul 2012
Posts: 106
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
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.
 
Old 11-20-2012, 09:59 AM   #6
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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.
Old 11-20-2012, 12:54 PM   #7
esgol
Member
 
Registered: Jul 2012
Posts: 106
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
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.?
 
Old 11-20-2012, 01:57 PM   #8
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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.
 
Old 11-20-2012, 02:10 PM   #9
esgol
Member
 
Registered: Jul 2012
Posts: 106
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
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.
 
  


Reply


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
zmq client server program ..my client is working but server is not..pls help batman4 Programming 2 08-13-2012 07:44 AM
Client Server program in C fahad.anwar Programming 1 07-24-2012 04:07 AM
Client Server Socket TCP/IP program in C Linux over HTTPS fahad.anwar Linux - Newbie 6 05-29-2012 03:59 AM
Client Server Socket TCP/IP program in C Linux using threads fahad.anwar Linux - Newbie 2 05-18-2012 04:34 AM
server client program swift2008 Programming 10 11-26-2008 12:12 PM


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

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