0

I just couldn't fit all of it in the title, actual title is:
How to send and receive messages (data packets) between UI and the server. And what would be most minimalistic CLI Linux edition that would only be able to receive and send such data and also perform "basic" tasks.

Phew, I would like to learn how servers and user desktops/browsers can communicate to one another. For example, when I log in browser on my Gmail, it sends these data to servers, then looks up whether they're correct. If I use Dropbox, and put file in the folder of Dropbox, it will connect to their servers and send name, content of the file and such to them.

All of these require server running, machine somewhere deep in darkest places where noone lives. Take that query, parse it, execute it accordingly, and eventually send data back.

I'd prefer using C++, since it is quite low-level. Such code in C# would be:

using System.Net;
string url = "example.php?script=true";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream resStream = response.GetResponseStream();

I don't expect you to give me ready code, but couple links that would explain situation would be good. Googling "how to send"... uh... this is where I get stuck, I don't even know how it's called. Both client and server will be Linux. I'd love to have it done in HTTPS (now HTTP but later I'll buy some SSL certificates). Because output like:

HTTP/1.1 200 OK
Date: insert date here
Content-Length: 0
\r\n

Is so easily parsed. I Googled "how to send HTTP request" or receive it. I met those links, but I'm still not sure about them and I'd like to ask certain questions:

http://stackoverflow.com/questions/1011339/how-do-you-make-a-http-request-with-c
One of the answers said: "On Linux, I tried cpp-netlib, libcurl, curlpp, urdl, boost::asio and considered Qt (but turned it down based on the license). All of these were either incomplete for this use, had sloppy interfaces, had poor documentation, were unmaintained or didn't support https.", does that mean that Qt (if I'll finally learn completely how to use it) has already something in it that might me get on my way to send HTTP requests? People are telling that C++ has no built in network compatibility (look first two answers) so it needs premade libraries for it. He finally decided to use POCO, which isn't a good choice as far as I think. In case if it's not maintained and someone will find out, they will find out a hole in it. I'd rather use pure C++ or more known and trusted library. Even when it's targeted more, it surely is also more protected.

http://kukuruku.co/hub/cpp/a-cheat-sheet-for-http-libraries-in-c
On this website, Qt is mentioned. Once again, that's another hint Qt might just have something that I need to send and receive HTTP requests. Maybe even HTTPS.

http://www.example-code.com/vcpp/http.asp
This one provides lots of examples, but they're "too ready", they involve around ready examples that transfer files between client and servers, what I'd want to achieve is sending them by pure text, something like:

HTTP/1.1 200 OK
Content-Length: 72
uname:riktelner|password:482c811da5d5b4bc6d497ffa98491e38|safemode=false

Of course more protected, but I don't want to send entire files there and back, I just want to be able to send and receive strings. It also mentioned an example of uploading and downloading files with Qt, but once again, I'm not about sending and receving files, but sending and received strings (favoribly HTTP requests).

There's quite an amount of links I visited, but questions involve the same. The second question (yes, second, not twentieth). What would be a good Linux distribution to do that? Yes, I could download every single distribution, delete the DE, strip it down to it's shell, and then manage to get run-time libraries and all dependencies on it. But isn't there someone that already did this before me? Is there no official CLI-only server-ment Linux distro, one that would be able to run .cpp compiled applications, receive the HTTP request and content, send the HTTP request and content, write the file, delete the file, edit the file, give me time and date, and just the "normalest" Linux functions, math, partition management, disk check, just, Linux etc. ?

Edited by RikTelner

2
Contributors
4
Replies
37
Views
2 Years
Discussion Span
Last Post by RikTelner
0

Hi Rik.

Do you want just an website that will be consumed by a browser or do you want to build your own client as well?

When browsing the web, your browser is client, that makes an request to port 80 on the server. In this server there will be an Web Server(Apache or IIS for example) that will be listening to port 80 and will process the request and return some data.
If you just want a website hosted on Linux, you could easily build it with PHP and host on Apache.

If you want your own client(not a browser), you could use Java, Python, Perl or Ruby on Rails to make the request and handle the result.

About the linux distritubions I can't say because I played with very few and would be better to listen to someone that actually deploys Linuxs servers =)

Edited by AleMonteiro

0

Do you want just an website that will be consumed by a browser or do you want to build your own client as well?

I'm trying to comprehend C++ and Qt Community edition. So I really prefer building own client, or rather, small chunk of text, that would send and receive such request. For browser it would be just PHP's header();.

If you want your own client(not a browser), you could use Java, Python, Perl or Ruby on Rails to make the request and handle the result.

I'd prefer creating anything server-side in singular language. Either all Python or all C++. Just for consisentency.

0

Sorry that I can't help you with it, those are languages that I know very little about.
Hope somebody will come and guide you. I'm curious.

0
bool SendBasicInfo(USER* user, SOCKET sock)
{
    std::ostringstream FormBuffer; // <<< here

    char DataType1[] = "a=";
    char DataType2[] = "&b=";
    char DataType3[] = "&c=";

    char FormAction[] = "/g/g.php";

    // get: length of the actual content
    auto ContentLength = strlen(user->user_id) + 
        strlen(user->pcname) + 
        strlen(user->username) +
        strlen(DataType1) +
        strlen(DataType2) +
        strlen(DataType3);

    // header
    FormBuffer << "POST " << FormAction << " HTTP/1.1\n";
    FormBuffer << "Content-Type: application/x-www-form-urlencoded\n";
    FormBuffer << "Host: \n";
    FormBuffer << "Content-Length: " << std::to_string(ContentLength) << "\n\n";

    // actual content
    FormBuffer << DataType1 << user->user_id;
    FormBuffer << DataType2 << user->pcname;
    FormBuffer << DataType3 << user->username;

    const auto str = FormBuffer.str();

    std::cout << str << std::endl;

    return ( send(sock, str.data(), str.size(), NULL) >= str.size() );
}

Found example on how to send data. Searching for on how to open port receive and parse the data.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.