Advertisement

data via internet?

Started by August 27, 2003 07:00 AM
6 comments, last by Bero_Avrion 21 years, 5 months ago
Hi there, I wanna realise an application that fetches data from a server. Since I don''t know anything about this, I''m looking for a easy solution. can I simply open a file that way: FILE *File=NULL; File=fopen("http://www.xyz.com/file.txt","r"); ??? (Maybe this is a very stupid question, but as I told, I never worked on something like that before...) Bero
OK, that wouldn''t work (I knew it was stupid! ), but since I use the Qt Library for C++, that isn''t the problem an more, it provides a special class for getting data from an URL.

But now, I have another problem: my programm should fetch some data from the server which can be modified by the user (no problems that far) and then he can upload it to the server.
Each user should have a own file, which he can modify, but all users should be able to download all files and view them (in fact, the programm should do this for them, but that doesn''t matter...) my problem is, how can I write a programm that modifies data on a server? As I told, I''m using Qt, but if there''s another (better) solution, please tell me!
Oh, I forgot: when running the programm first time, it should create the users file on the server.

Bero
Advertisement
Ok, only programs on the server can modify data on that server (which is good, because programs on the client machine can never be trusted). However, since you want the clients to be able to modify data on the server, the problem becomes communication. The clients must communicate with a program on the server to request that the data must be changed, and then the program on the server must verify that the change request is valid, and then change the data.
So now the problem is split into writing the client so that it can communicate with a program on the server, and writing the program that runs on the server. I don't know what you're allowed to do on your server, but there are various options.

If you can run anything on the server (possibly because you're running the server machine yourself) then one solution is to write your own program that will accept connections from clients, and handle the requests. But that will be difficult and take quite a while (longer if you don't know much about networking - which I'm assuming you don't). It's also difficult to write server programs in such a way that they are totally robust and reliable. Qt's networking classes will help with this, but it still won't be easy. In this situation, you would design your own protocol for communicating between client and server, and you would write both programs to use this protocol.
The second solution, which will work if you control your server completely, or if you are allowed to run some form of cgi script on your server (for example, php scripts, perl scripts, etc) is to use HTTP to pass requests from client to server. The webserver will process the request, and then run the relevant script to pass the result back. Your job then becomes writing the server side scripts, and writing the client to send those requests. Qt already provides methods for sending HTTP requests, as you've found out - since HTTP is the protocol you're using to get data from a URL. Exactly the same process could be used to send a request to change data, you just have to pass a different URL. So the client is easy with this method. The server side scripts will almost certainly be pretty easy too (even more so if you already know a scripting language that you can use).
The final solution should only be used as a last resort, if your server only lets you put static pages on it. You can use FTP in your client just as you use it to upload pages to the server normally. This solution is very insecure though, since anyone who gets the client can modify it or simply extract the FTP password for your server from it, and instantly be able to change anything they want on your server.

I think your best option would actually be number 2. It should be fairly easy to set up if you can run scripts on your server, it requires very little work (the hardest part will be writing the scripts - and that will probably be quite easy since the scripting languages like php have large libraries of built in functions for you to use) but it should be quite secure as long as you write the scripts correctly.

John B

[edited by - JohnBSmall on August 28, 2003 9:32:47 AM]
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
Hey, thank you very much!

Since I don''t run the server myself, I can''t realize version 1.
Version 3 seems quite easy (at least with Qt), but I think I''ll stick to No.2 (security rules ) unfortunately, I don''t know how to write the scripts.
You don''t know a good tutorial page for this kind of scripts (or a book), do you (or anyone else)?

Thanx for the help,
Bero
Well, I suggest you search on google for whatever scripting languages your server host will let you use, and look into each one (probably write a few very short test scripts) to see which you like most, and then continue to search for more information about that one.
It''s a matter of opinion of course, but I would recommend php, if your server provides for it. The syntax is quite easy to learn if you know C or C++, and it has a very extensive library of utility functions. You can find out about php from www.php.net (probably best to start with the introductory tutorial). Although it''s obviously designed for outputting HTML pages, and the examples in the tutorial have that in mind, it''s just as easy to make it output other formats (bear in mind though that string based formats are probably easier to output than binary formats, since php includes so many useful string manipulation routines). Other php tutorials should be easy to find with google, if you need them, although the main documentation is very good in my opinion, and will usually tell you everything you need.

John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
If you need to store information, you could use MySQL to do so. It''s very easy to create a simple console application, which logs on to a MySQL server and uploads/downloads information.
Advertisement
quote:
Original post by Snash
If you need to store information, you could use MySQL to do so. It''s very easy to create a simple console application, which logs on to a MySQL server and uploads/downloads information.

While this would be a good way of storing the information, and I recommend it if it''s available, it would not be secure to let the client connect directly to the MySQL server. This is for the same reason that letting the client connect directly to the server with FTP would not be secure. Although you can alter the database permission settings so that clients can only view the data, and not change it, this would defeat one of the requirements of the system (that the user can change their own information). You can''t restrict a client to let it change only its own record with MySQL permissions, so for security you have pass the data through an intermediary such as a php script.

John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
Well, so it seems that I should use PHP. I'm familiar to html, but PHP is (nearly) complete new to me, but I'm always willing to lern some new cool stuff!
If someone of you knows a good tutorial, please let me know. For the beginning, i'll stick to the "official" php.net-tut's

Thanx to all of you, [edit]<- should be "both of you"
Bero

[edited by - Bero_Avrion on August 28, 2003 3:57:46 PM]

This topic is closed to new replies.

Advertisement