Jump to content

  • Log In with Google      Sign In   
  • Create Account


Networking engine design trouble


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Ripiz   Members   -  Reputation: 529

Like
0Likes
Like

Posted 26 March 2012 - 06:54 AM

Hello,

In my free time I'm trying to learn programming and I decided trying to make game should be good experience, therefore I picked MMOG (please no trolling). I've tried to find some networking library however I failed, so I decided to try and make my own one, or at least something that simplifies networking. I decided to go with semi-RPC way: non-blocking RPCs where return value is another RPC. However I ran into little design issue.

Lets say main loop on client looks like this:
void MainLoop() {
    HandleInput();
    UpdateFrame();
    RenderFrame();
}

/* somewhere inside one of functions player sends data to server */
/* for example chat message, login request, etc */

// currently I planned it'd look like this:
string username = ...; // get input from GUI
string password = ...;
client->Call("Login", username, password);
/* Call() serializes parameters and sends them over network to server using sendto() function */

/* on server side function will be called */
void Login(string username, string password) {
    if(database.FindAccount(username, password))
        server->Call("LoginReply", "success"); /* where to send data? */
}

Therefore right now I cannot seem create proper design that'd allow me to send reply back easily.
I was hoping someone could help me out with this issue. Maybe even whole idea is wrong and there are better solutions?

Thank you in advance.

Sponsor:

#2 Madhed   Crossbones+   -  Reputation: 2786

Like
0Likes
Like

Posted 26 March 2012 - 07:55 AM

What do you mean "you tried to find anetwork library, but failed"? You didn't find any, or the ones you found where not fit for your project?

Did you check out RakNet? I used it before and it's pretty good.

#3 Antheus   Members   -  Reputation: 2397

Like
0Likes
Like

Posted 26 March 2012 - 08:34 AM

/* where to send data? */
}


A common approach is publish/subscribe (or observer pattern for non-network). Communication is bi-directional, but independent. Each end listens to messages and replies at leisure. Server looks like this:
// Client is created by server whenever a new connection is accepted. it then uses that class to deal with it
class Client {
  // the rest
  socket s;
}

List<Client> clients;

void onMessage(Client c, Message m) {
  // decode message
  // handle it
  c->send(ReplyMessage);...
}
Server and client here are free to send messages as they wish. If you need a request/response, include some type of tag into message. Can be a random number, hash code or some sequential identifier, something unique.

#4 Ripiz   Members   -  Reputation: 529

Like
0Likes
Like

Posted 26 March 2012 - 09:10 AM

Well RakNet is somewhat nice, but it costs money (commercial license);
Similar issue with Zoidcom (http://www.zoidcom.com/);
HawkNL seemed just like simple wrapper to low level functions (socket(), listen(), send(), etc);
enet is just general networking lib (connection, disconnection, etc);
ZIG is a bit higher level, feature or two towards games (client_id in connection/disconnection/packets), however all received data falls into single function, that would still require major wrapper, but overall I think this one is best in the lislt;
There were more libraries but I cannot find them right now to tell what was unsuitable.

Antheus, thank you for advice. I'll try that approach.

#5 Madhed   Crossbones+   -  Reputation: 2786

Like
0Likes
Like

Posted 26 March 2012 - 09:37 AM

Well RakNet is somewhat nice, but it costs money (commercial license);


They offer a non-cost Indie license though... anyways, not trying to sound like a sales rep here. ;) If you want to build your own that's cool too.

#6 hplus0603   Moderators   -  Reputation: 5164

Like
0Likes
Like

Posted 26 March 2012 - 10:44 AM

In my free time I'm trying to learn programming and I decided trying to make game should be good experience, therefore I picked MMOG (please no trolling). I've tried to find some networking library however I failed, so I decided to try and make my own one


If you don't even know how to program, you are doomed to failure in this effort. Networking (or, in the general sense,) distributed systems, is a hard area of systems programming, which you typically don't even start learning about until several years in on a university computer science program -- for a reason.

Currently, it sounds as if you're not even at the point where you would be able to tell whether a library would be suitable or not. Starting with RPC is probably the first mistake -- that is not a generally useful approach for large, fine-grain distributed systems, for reasons that have been explained in literature.

I suggest you first learn to program, using something really simple, like Space Invaders or Tetris (this will still be pretty hard.)
enum Bool { True, False, FileNotFound };

#7 FlyingDutchman   Members   -  Reputation: 207

Like
1Likes
Like

Posted 22 April 2012 - 01:19 AM

If you really really want to learn how to do network programming, I would suggest you install Unix first and than read the book Unix Network Programming by W. Richard Stevens. This is an awesome book which covers most of the BASIC aspects of Unix server side coding like Polling, Asynchronous I/O (crucial) etc.. If you than have a thorough understanding of how the basic stuff works you can use to high level libraries like Boost::ASIO , which leverage a lot of work for you and provide a simple but efficient interface to handle at least a couple of hundreds clients.
Of course you could use a dedicated library straight from the beginning but especially in a field like networking it is often necessary to have an understanding about whats going on under the hood. Especially when you need to customize stuff. The cool thing about studying unix sockets is that it will also tell you alot about how unix works in general. It is really an eye opener to get an understanding of file descriptors etc..

I open sourced my C++/iOS OpenGL 2D RPG engine :-)


See my blog: (Tutorials and GameDev)

http://howtomakeitin....wordpress.com/


#8 hplus0603   Moderators   -  Reputation: 5164

Like
0Likes
Like

Posted 23 April 2012 - 10:07 AM

install Unix first and than read the book Unix Network Programming by W. Richard Stevens


I second this suggestion -- it's a great thing to do if you want to get into networking (and thus systems programming and distributed programming.)
Learning the UNIX environment, including the shell command line, is also a good way of getting a better understanding of how to automate systems and make them robust without operator intervention.
And it's easy to get started -- download an Ubuntu "live CD" and/or install as an application for Windows. Or use a virtual machine. Highly recommended.
enum Bool { True, False, FileNotFound };




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS