# Networking engine design trouble

This topic is 2345 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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?

##### Share on other sites
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.

##### Share on other sites
 /* where to send data? */ } [/quote]

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.

##### Share on other sites
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.

##### Share on other sites

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.

##### Share on other sites
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[/quote]

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.)

##### Share on other sites
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..

##### Share on other sites
install Unix first and than read the book Unix Network Programming by W. Richard Stevens[/quote]

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.

1. 1
2. 2
3. 3
Rutin
18
4. 4
5. 5
JoeJ
13

• 14
• 10
• 23
• 9
• 49
• ### Forum Statistics

• Total Topics
632639
• Total Posts
3007587
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!