Conversation started Nov 21, 2012 at 2:49.
Nov 21, 2012 02:49
hey every1, i have an engine class in c++ that when run either creates a server or client. i have some engine functions that iw oudl like to call in the server/client, but dont want to store a pointer back up to the engine. would it make sense for the server and client to inherit from the engine?
Nov 21, 2012 03:30
storing a pointer is usually the better way
but then that means the engine and client for exmple will be strongly coupled, because the engin creates a client and the client has to store a pointer to the engine that created it.... thats bad right?
"strongly coupled by composition" is still much weaker coupling than inheritance
or you mean, the user has to know this
in which case, you can hide the engine constructors behind some method that just gives "makeClientEngine" or "makeServerEngine"
i...........................c
the biggest issuei have right now is that from the client, you can create a new server in its own process.. like if you decided to host a game for example
but im not sure how to do that from the client... i would have to go back up to the engine and request it to be done right?
you can think of a full standalone single player as basically being one server + one client that are just holding hands
"requesting a server" is something like exposing a network interface to something you already have internally
Nov 21, 2012 03:45
my design was to start a client only, because if you want to join a dedicated server, i dont want to have a local server running all the time because it would waste resources... or can i make the server process sleep somehow and not take away any performance when im connecting the client to a remote server?
I don't mean you have to run the server as a separate process
i mean it was my choice to do so....
but what i wanted to know is if its possible to run say a client and a server process, but now have the server process eat up resources?
because if the server process doesn't eat up resources then i hav no problem having it running all the time while i play on some remote server...
what resources would it eat up?
well it will have its own continuous loop running eating up cpu i would guess
but it would have nothing to do
I presume the server process has some Start() method that you call to initialize "hosting a game" and some Stop() method to you call to dispose of everything.
Nov 21, 2012 03:54
o yes that is true
while your player is in the menus before jumping "into the real game"
your server shouldn't be doing anything
or you could start the server immediately but then stop it when the client joins a remote server
i wnat the server to pretty much identical to a dedicated server though... the dedicated server would just loop continuously looking for connections.. if my server isnt running then i have to figure out someway to start it before i can send connection packets to it right? this is assuming i put it in a seperat eprocess
the client just says "I'm going to play with someone else, you should take a nap and unload all your resources"
the reason being identical is so i dont have to change any code
"looping continuously looking for connections" isn't really that expensive
especially since most "listen" type interfaces have aome kind of built-in timespan to wait
Nov 21, 2012 03:56
but it is not limited by any kind of sleep or anything... so it will run as fast as possible right? eatup allmy cpu?
but i mean in a real game scenario the server will be doing all of its serving duties so it isn't sitting waiting for connections... it just polls for any connection requests when it has time to
no, it will not run as fast as possible. for example, the last parameter in select is a timeout value
couldn't you run the poller in another thread?
thats what i was trying to avoid lol
the loop for the server is like
while (true)
{
peek for any connection requests.. none? ok

process...
process..

}
so it doesnt wait at all it just checks to see if any request came in since the last time it checked
well
I wouldn't write it that way
but even if you do
while(true) {
    if (this.currentClientCount == 0)
        peek(50ms timeout)
    else
        peek(0ms timeout)

    process()....
}
hm
that sounds like a good idea
or, in your client, when you connect to a remote server, first you connect to your local server, send a "standby" command, and then go off and play
Nov 21, 2012 04:02
i will try doing that but just curious what way would u write it?
ok but then when my server gets a standby command how can i be sure that it is the local client that sent it and not a rogue user?
well, I'd use a separate thread ;) easier to reason about that way
lol
i will make a branch for both approaches
and then wheni finish both branches ill flip a coin
regarding anti-rogues: well, because your server has some method of authentication
ok good call
also, any kind of sanity check, such as "I will not standby if there's any players currently playing other than the player who ordered standby"
Nov 21, 2012 04:04
good idea
well thank you for the help youve given me a couple ideas on how to get started with this solution
how do i upvote your messages?
no prob
there's no reputation in chat
o :(
 
Conversation ended Nov 21, 2012 at 4:05.