PDA

View Full Version : gift to all networking noobs (as i am)...



daemonna
17th September 2010, 00:34
after finding lot of helpfull people here, i've decided to give something back (actually my own mutant-fork of closed source project), so i gave birth to

http://code.google.com/p/elementalserver/

and i hope this code will help many noobs to learn how does qt networking work.

wysota
17th September 2010, 00:42
Yes, of course it's threaded.... Geeeeez people, what's with you!?

daemonna
17th September 2010, 00:44
if you don't like threads, you can help write single-threaded version ;)

wysota
17th September 2010, 07:10
I do like threads but not in this context. By giving such a code to people you are encouraging them to learn bad habits, this code is just wrong (both conceptually and technically), overbloated and unnecessary. If you want to give someone an example then make it simple.

daemonna
17th September 2010, 10:31
this code is just wrong (both conceptually and technically), overbloated and unnecessary.

how can i know if something is wrong? only from people like you... but just to say 'it's wrong' it's not enough. What is wrong? How can it be improved? Do you have specific workaround for this and that?

...if NOT, it's just useless non-productive talk from your side.

By giving such a code to people you are encouraging them to learn bad habits

No! this is GOOGLE CODE! i dont encourage anyone to anything... you can take it or leave it.... or help improve it (best choice). I'm not saying "this is best software on planet", but saying "this is my piece of code, please, take a look and help improve.. and if you like it, share it."... coz this will be software for YOU people, not only for me....

so please, dont forget you have to get hands dirty, before talking dirty... :P

wysota
17th September 2010, 10:50
this code is just wrong (both conceptually and technically), overbloated and unnecessary.

how can i know if something is wrong?
If you don't feel confident enough that your code is not wrong, don't post it as an "example" to others.


only from people like you...
You should know it based on your knowledge.


Do you have specific workaround for this and that?
It's not a matter of workarounds, it's a matter of concept.


...if NOT, it's just useless non-productive talk from your side.
I already told you my doubts in another thread. And my (and not only mine) opinions about such network programming are scattered all over this forum. If that's not constructive enough for you, you'll have to wait about a month.


By giving such a code to people you are encouraging them to learn bad habits

No! this is GOOGLE CODE!
No, this is QtCentre forum:

and i hope this code will help many noobs to learn how does qt networking work.

daemonna
17th September 2010, 11:41
i got your point, but as i said before..


without your contribution , your comments are useless for me...

looks like you're coming from windows userbase and have no clue about contribution and sharing for FREE... do you? :)


my (and not only mine) opinions about such network programming are scattered all over this forum

that's right, and that's why these opinions are useless, coz they are scattered all over and are just opinions without showing something 'that works' and is 'not wrong and bloated'. Or maybe it's problem with search engine, because if i put there 'single thread server', i'll find just questions without actuall answers. i thought this suppose to be forum TO HELP, not to flame, argue and blame someone 'your design is wrong'....

if you have at least little will to help, download code... fix what you think can be fixed or make a 'new design' document (or whatever) , and mail me changes. dont forget it's your choice to IMPROVE IT, CONTINUE with your useless 'it's wrong'-attitude (coz saying 'it's wrong' is no help at all) or simply IGNORE it.... so make your choice!

wysota
17th September 2010, 11:46
looks like you're coming from windows userbase
No, not really.


and have no clue about contribution and sharing for FREE... do you? :)
Forgive me, I will not answer this question. You should be able to find the answer to this one on your own.

nish
17th September 2010, 11:55
i always like ppl who post their code on to the web. so gud job @daemonna. But the guy u r talking to is very experienced, so take his comments as positive.

JohannesMunk
17th September 2010, 11:56
Daemonna, it's obscene to tell wysota with 19k messages and >2k thanks, that he doesn't know about contribution and sharing.

Put that attitude back where it came from!

Johannes

daemonna
17th September 2010, 12:03
Forgive me, I will not answer this question.

there's nothing to forgive wysota... it's your choice to contribute or not.. and i dont blame if you will not contribute. but i simply dont accept "this is wrong" statement without proper explanation and piece of code that WORKS good way. Open source community is live only thanks to people that come and give SOLUTION, not a people that come, complain and go...

so dont take me wrong, i'm only gives here something that works (maybe wrong way, but it works) and can be changed by anyone to be better and to prosper to community.

People! i'm not trying to put blame/flame/p*** on wysota head... NO! i know he's VERY experienced and probably knows more than anyone else, but saying only "THIS IS NOT GOOD" doesnt make him any better than any flamer. I ask for help, not personal help which gains me money, but help for OPEN SOURCE project to make it better (coz i'm not guru at all) and saying only "it's wrong" is like telling african children "go and find some food if you're hungry"... it's NO HELP AT ALL.

wysota
17th September 2010, 12:57
Forgive me, I will not answer this question.

there's nothing to forgive wysota... it's your choice to contribute or not..
Yes, it is my choice to contribute or not :) I'm happy I made the right choice.


but i simply dont accept "this is wrong" statement without proper explanation
I already gave you a proper explanation.


and piece of code that WORKS good way.
There is such a piece of code already in Qt docs.


so dont take me wrong, i'm only gives here something that works (maybe wrong way, but it works) and can be changed by anyone to be better and to prosper to community.
I'm sorry, but in my opinion each existing wrong solution puts people one more step away from finding the proper solution. I just don't share your point of view that a poor solution is better than no solution. Sooner or later this poor solution will explode in your face and you'll waste more time trying to patch it up than you'd spend thinking how to do it properly in the first place.


saying only "THIS IS NOT GOOD" doesnt make him any better than any flamer.
Suit yourself, I didn't want to make you feel bad but if you insist:
- your application is leaking memory
- your server is prone to DOS attacks
- you are using shared memory for something that is completely irrelevant to the server and thus it makes no sense to put it in this 'example'
- your shared memory thread has no exit condition (so your program is likely to never finish)
- using a thread for your shared memory stuff is a pure waste of resources, the same could be achieved without using sleep, i.e using idle processing
- you are using signals and slots with QThread in a wrong way
- you are needlessly subclassing QThread
- I have no idea why you operate on byte arrays in such a complicated way
- you are putting literally everything into threads, even single method calls (even the non-blocking QTcpServer::listen()), God only knows why
- you are using arbitrary values for.... yes, I have no idea why you are doing that...
- you are using global/extern variables instead of encapsulating them properly (and you are using them across threads)
- your archive has the size of almost 1.5MB, a bit much as for an "elementary example"
- you should really read this: Keeping your GUI Responsive (http://doc.qt.nokia.com/qq/qq27-responsive-guis.html) (just be careful, it's written by someone who doesn't contribute)
- and this one too: You're doing it wrong (http://labs.qt.nokia.com/2010/06/17/youre-doing-it-wrong/)

If you want to share code -- good, I don't mind. But don't call it an "example". An example should be short, to the point and flawless.

daemonna
17th September 2010, 13:20
finally Guru said something wise....


THANKS!

daemonna
17th September 2010, 14:39
regarding your amends:

now I see I need to seperate it, one for single/easy work, another for multi-threading... but to clear things up, primary job of server will be some usefull job, so dont take it only as 'example'...


- your application is leaking memory
probably yes, but i still study how to work with Valgrind to check that...

- your server is prone to DOS attacks
is truncating packets to small size (let's say 500bytes) enough? Is there any guru tutorial how to avoid DOS attack?

- you are using shared memory for something that is completely irrelevant to the server and thus it makes no sense to put it in this 'example'
coz it also suppose to be example of sharedmemory among threads, but yes, i'will probably kick that code out...

- your shared memory thread has no exit condition (so your program is likely to never finish)
- using a thread for your shared memory stuff is a pure waste of resources, the same could be achieved without using sleep, i.e using idle processing
- you are using signals and slots with QThread in a wrong way
- you are needlessly subclassing QThread
WE ALL DOING IT WRONG THANKS TO DOCS THAT HASNT BEEN UPDATED... just see comments on http://labs.qt.nokia.com/2010/06/17/youre-doing-it-wrong/comment-page-1 . But I promise I will try to learn it doing it right, thanks to your link.

and in "threading-without-the-headache" is nice comment

Nice example. However, you do have a hiden lock — the one that Qt uses for signalling across threads, right?
Also, this only works with 1-1 producer/consumer, not for MxN setups.

so I wasnt doing it that much wrong, because original project is multi-user multi-game server... not single game session. that's why i did it such complicated way...

wysota
17th September 2010, 15:00
now I see I need to seperate it, one for single/easy work, another for multi-threading... but to clear things up, primary job of server will be some usefull job, so dont take it only as 'example'...
A good example is something to build upon.


- your application is leaking memory
probably yes, but i still study how to work with Valgrind to check that...
You don't need valgrind here, just look at your code.


- your server is prone to DOS attacks
is truncating packets to small size (let's say 500bytes) enough?
This is not a problem.


WE ALL DOING IT WRONG THANKS TO DOCS THAT HASNT BEEN UPDATED... just see comments on http://labs.qt.nokia.com/2010/06/17/youre-doing-it-wrong/comment-page-1 .
You can't blame pure virtuality of QThread::run() for all your thread problems. The nature of using QThread never changed and all that was explained in the docs, it was still suggested to call QThread::exec() from within QThread::run and work on objects.


so I wasnt doing it that much wrong, because original project is multi-user multi-game server... not single game session. that's why i did it such complicated way...
I think you misunderstood the comment. It doesn't say that you can't have multiple clients without threads.

daemonna
17th September 2010, 15:23
regarding threads i have to admit i didnt understand them well till your pointing tutorial... another thing to learn :)

regarding memory leak just look at your code is not enough, i got more programming/admin/study stuff in my head, so i dont think pure look will suffice... that's why Valgrind.

regarding DOS attack i can quickly imagine only 2 DOS attacks.. one is overflow socket with too many packets (so responce delay should help.. aka sleep() ), second is that packets are too big (that's why to truncate big data)...

regarding last point, i dont talk about multiple clients here... i talk about multiple games in 1 process and each game can have multiple players... this is something completely different and only substitute i see here is some kind of clustering.

wysota
17th September 2010, 16:44
regarding memory leak just look at your code is not enough, i got more programming/admin/study stuff in my head, so i dont think pure look will suffice... that's why Valgrind.
You are not deleting any objects you allocate.


regarding DOS attack i can quickly imagine only 2 DOS attacks.. one is overflow socket with too many packets (so responce delay should help.. aka sleep() ), second is that packets are too big (that's why to truncate big data)...
Third is too many clients connecting at the same time, fourth is existing (broken or malicious) clients staying connected forever reaching the limit of clients allowed.


regarding last point, i dont talk about multiple clients here... i talk about multiple games in 1 process and each game can have multiple players... this is something completely different and only substitute i see here is some kind of clustering.
Honestly I don't see how the comment from labs is related to what you say and how it is related to what I said.

daemonna
17th September 2010, 17:54
You are not deleting any objects you allocate.

Third is too many clients connecting at the same time, fourth is existing (broken or malicious) clients staying connected forever reaching the limit of clients allowed.


i'm still little bit confused about constructor/destructor working in QT4. Is it only children of QObject that will be automatically destructed??? so anything else i have to write destructors myself??

regarding DOS attack:

if i'm not wrong, with QTcpServer::setMaxPendingConnections is easy to set max clients and to check if client is idle is also easy with QTime::elapsed ()

Zlatomir
17th September 2010, 18:20
i'm still little bit confused about constructor/destructor working in QT4. Is it only children of QObject that will be automatically destructed??? so anything else i have to write destructors myself??

Only classes that are derived from QObject can be part of a parent-child relationship, and the parent is responsable to delete his own childrens, when the parent goes out of scope (if the parent is created on the stack) or when the parent gets deleted (if the parent was created on the heap and does not have another parent)
Here is a simple Hello world example:


#include <QtGui>

int main(int argc, char** argv) {

QApplication app(argc, argv);

QWidget *w = new QWidget(0);
QLabel *l = new QLabel("Hello Qt World!", w);

w->show();

int ret_val = app.exec();

delete w;

//we must delete 'w' because: 1) we create it on the heap 2) it doesn't have a parent

//we don't delete 'l', because 'w' it's his parent and will take care of deleting 'l' for us
//if you try to delete 'l' you might get some "segmentation fault" errors

return ret_val;
}

wysota
17th September 2010, 18:27
if i'm not wrong, with QTcpServer::setMaxPendingConnections is easy to set max clients
"max pending connections" has nothing to do with the maximum number of clients. It's the size of the backlog for ::listen().


and to check if client is idle is also easy with QTime::elapsed ()
I surely wouldn't do that with QTime::elapsed(). You are still thinking in a synchronous manner.