Jump to content


Photo

Little Curious how Multiplayer Works


Best Answer kicken, 12 September 2013 - 08:57 PM

When you say a persisten socket, does this mean the chat table is being queried like every second in essense?( For a chat room for example) or only when new data is available?

By a persistent socket I mean you connect once, then just send data to/from the server, rather than constantly connecting/sending/receiving/disconnecting which is what http normally does. Having a constant connection allows the server to be able to push data to the browser when it is necessary, rather than the browser having to constantly check in with the server to see if anything has changed. If there is no changes, no data is sent saving bandwidth and processor power.

As far as querying the chat table, that all depends on how you want to setup the server side of things. You could just have your server setup so that when someone sends a message, the server accepts it and then re-distributes it to all connected clients and never even involve a database table. This is how IRC works for example. If you wanted to store a complete chat history then you'd still need to write it to a table, but you only need to write it, not re-select it for each client.
 

Even if it does do it when new data is available a simple 10-20room chat room with all active users using socket.io wouldn't that just rape the server?


# of rooms is irrelevant. # of connected clients is what you need to be concerned with. 1 room with 100 people is the same load as 10 rooms with 10 people each, more or less. How many clients your server would be capable of supporting depends on how well the chat software is coded and server specs. A low-end VPS (512-1gig ram) should easily be able to handle a few hundred users. Depending exactly on what you need/want the chat to do obviously.
 

Would this be why sometimes if u DC you lose data on ur character because it wasn't saved to Server? (Wouldn't this need to be updated like every second as well) for no data loss?


Possibly, although just because the client disconnects does not mean the server would fail to save the data. For that to happen, something would have to happen on the server end, such as a crash or power outage.
 

How do these servers perform so good under these load, I dont get it :/


Also you need to keep in mind that these big MMO's you compare to have LOTS of servers, possibly with some pretty high-end specs. Also, keep in mind that a lot of the interaction with the database is going to be SELECT queries, just reading out things like character/mob specs, loot tables, etc. There would be quite a bit fewer write operations going on. To handle all the SELECT's you use replication to distribute the load among several different slave read-only DB servers. Write operations would be directed at the master server which then relays those changes to all the slaves.
 

Also, does every windows programmed MMO/Multiplayer  game have to use Winsock?


Every piece of windows software that connects to a network at all uses winsock. Winsock is windows' sockets implementation which drives all socket base communications. Go to the full post


  • Please log in to reply
7 replies to this topic

#1 Monkuar

Monkuar

    Advanced Member

  • Members
  • PipPipPip
  • 874 posts

Posted 12 September 2013 - 08:35 AM

I'm curious how a client or game connects to mysql and updates it.

 

In Path of Exile, u have a item that lets you change the amount of sockets a item has.

 

For instance, everytime when a user uses the item (They could have over 2000) on the item.... is it in essence 1 MYSQL UPDATE EACH time? (1 query)? Or how exactly does it register through the server or sustain lower optimization or performance?

 

i know this sounds dumb, but I've always wondered this stuff.  If that is true, wouldn't those queries and all the active users just rape the servers?  

 

I've looked into socket.io / etc is that kind of like the same thing as Winsocket? (Wouldn't this be even MORE server intensive with an active connection?) 

 

Just curious, I know you guys think I am clueless and have no idea what im talking about, but please...

 

Also, im curious on why people say socket.io is better? If you have a chat system using socket.io and 5 active users.  It's constantly refreshing and querying from the chat table to display all the data right? Wouldn't a simple ajax poll every 2-3 seconds would be fine? O_o  I know this wouldn't really work for MMO's because it would be laggy data, but then in essence is that socket.io grabbing all the data from the chat table (querying it) every second? Wouldn't that just destroy the server @_@


Edited by Monkuar, 12 September 2013 - 08:43 AM.

I learn more on this site than I did in K-12 Grade...  (Barand Is a MYSQL King) I dont offer help to anyone anymore because I am the the person who needs help....

"Even if I did learn php 100% I wouldn't even be smart enough to use it..." - monkuar

#2 ignace

ignace

    Now mod flavored

  • Moderators
  • 6,208 posts
  • LocationBelgium

Posted 12 September 2013 - 09:13 AM

You are gonna be more specific. I have no idea what you are talking about.

#3 Irate

Irate

    Advanced Member

  • Members
  • PipPipPip
  • 358 posts
  • LocationHamburg, Germany
  • Age:17

Posted 12 September 2013 - 03:56 PM

For the chat thingy, there's also something called Comet. It's basically reverse Ajax.
Quod placet mihi non placeat tibi. - What I think to be good must not always equal your perception of it.

I am not perfect. I try a lot with the code I provide and I don't guarantee for it to work as I have mostly no option to test it on my mobile phone. I do apologize for any inconvenience I caused, but if I do happen to have helped, liking my posts or marking them as to have solved or answered your question would be nice.

#4 kicken

kicken

    Wiser? Not exactly.

  • Gurus
  • 2,568 posts
  • LocationBonita, FL

Posted 12 September 2013 - 04:01 PM

For instance, everytime when a user uses the item (They could have over 2000) on the item.... is it in essence 1 MYSQL UPDATE EACH time? (1 query)? Or how exactly does it register through the server or sustain lower optimization or performance?

I would imagine (but have no pratical experience/knowledge) that a game server most likely handles a lot of the operations/changes that need done in-memory and has some kind of background thread which will periodically save changes to the database. That way it would be able to service all the clients quickly without waiting on the database.
 

Also, im curious on why people say socket.io is better? If you have a chat system using socket.io and 5 active users.  It's constantly refreshing and querying from the chat table to display all the data right?


No, socket.io is just a wrapper for various ways of establishing "real-time" two-way communication. Exactly what it does depends on what the browser/server supports. A modern browser with Websocket support would just keep one persistent socket open to send data through. A browser Flash support uses some small flash program to emulate websockets. A browser with XHR will use either long or short polling, depending on what your server supports.

This ability for socket.io to adapt to what is available is why it is popular. It will use the most efficient method it can while keeping a constant api for your application to use.
 

Wouldn't a simple ajax poll every 2-3 seconds would be fine?


Sure, you'd just have a lot of unnecessary requests constantly checking on things. If it is the only method available though, then that is what you do.
Recycle your old CD's, don't trash them!
Did I help you out?  Feeling generous? I accept tips via Paypal or Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7

#5 Irate

Irate

    Advanced Member

  • Members
  • PipPipPip
  • 358 posts
  • LocationHamburg, Germany
  • Age:17

Posted 12 September 2013 - 04:48 PM

kicken, I mentioned Comet above, in response to the last point you quoted ;)

That does quite reduce the unnecessary Ajax requests to a minimum. All it requires is an open connection on the client side.
Quod placet mihi non placeat tibi. - What I think to be good must not always equal your perception of it.

I am not perfect. I try a lot with the code I provide and I don't guarantee for it to work as I have mostly no option to test it on my mobile phone. I do apologize for any inconvenience I caused, but if I do happen to have helped, liking my posts or marking them as to have solved or answered your question would be nice.

#6 Monkuar

Monkuar

    Advanced Member

  • Members
  • PipPipPip
  • 874 posts

Posted 12 September 2013 - 05:46 PM

A modern browser with Websocket support would just keep one persistent socket open to send data through.

 

When you say a persisten socket, does this mean the chat table is being queried like every second in essense?( For a chat room for example) or only when new data is available? Even if it does do it when new data is available a simple 10-20room chat room with all active users using socket.io wouldn't that just rape the server? How does MMO's do it with World/Trade chat? Thousands of active users just querying that table/refreshing it across all people, seems a bit overlord?

 

 

Kicken

I would imagine (but have no pratical experience/knowledge) that a game server most likely handles a lot of the operations/changes that need done in-memory and has some kind of background thread which will periodically save changes to the database. That way it would be able to service all the clients quickly without waiting on the database.

 

Would this be why sometimes if u DC you lose data on ur character because it wasn't saved to Server? (Wouldn't this need to be updated like every second as well) for no data loss? How do these servers perform so good under these load, I dont get it :/

 

I'm am making a web based RPG, I got inventory system done with jquery/drag/drop/monster battle AI/loot functions to give loot based on char level/etc (when monster died) /etc/etc, but if I do PVP it will obviously be turned based, but not sure if I want to do comet/longpolling/simple 1-2sec ajax/socket.io....

 

I also looked into the server files for a Diablo 2 Private Server, they store all character data into a .d2cs file or something on the server, then that file get's written everytime a person finds a item or whatnot, (get's read and written from the client) which we don't got source code for, only David Brevik does.

 

Also, does every windows programmed MMO/Multiplayer  game have to use Winsock?


Edited by Monkuar, 12 September 2013 - 05:48 PM.

I learn more on this site than I did in K-12 Grade...  (Barand Is a MYSQL King) I dont offer help to anyone anymore because I am the the person who needs help....

"Even if I did learn php 100% I wouldn't even be smart enough to use it..." - monkuar

#7 kicken

kicken

    Wiser? Not exactly.

  • Gurus
  • 2,568 posts
  • LocationBonita, FL

Posted 12 September 2013 - 08:57 PM   Best Answer

When you say a persisten socket, does this mean the chat table is being queried like every second in essense?( For a chat room for example) or only when new data is available?

By a persistent socket I mean you connect once, then just send data to/from the server, rather than constantly connecting/sending/receiving/disconnecting which is what http normally does. Having a constant connection allows the server to be able to push data to the browser when it is necessary, rather than the browser having to constantly check in with the server to see if anything has changed. If there is no changes, no data is sent saving bandwidth and processor power.

As far as querying the chat table, that all depends on how you want to setup the server side of things. You could just have your server setup so that when someone sends a message, the server accepts it and then re-distributes it to all connected clients and never even involve a database table. This is how IRC works for example. If you wanted to store a complete chat history then you'd still need to write it to a table, but you only need to write it, not re-select it for each client.
 

Even if it does do it when new data is available a simple 10-20room chat room with all active users using socket.io wouldn't that just rape the server?


# of rooms is irrelevant. # of connected clients is what you need to be concerned with. 1 room with 100 people is the same load as 10 rooms with 10 people each, more or less. How many clients your server would be capable of supporting depends on how well the chat software is coded and server specs. A low-end VPS (512-1gig ram) should easily be able to handle a few hundred users. Depending exactly on what you need/want the chat to do obviously.
 

Would this be why sometimes if u DC you lose data on ur character because it wasn't saved to Server? (Wouldn't this need to be updated like every second as well) for no data loss?


Possibly, although just because the client disconnects does not mean the server would fail to save the data. For that to happen, something would have to happen on the server end, such as a crash or power outage.
 

How do these servers perform so good under these load, I dont get it :/


Also you need to keep in mind that these big MMO's you compare to have LOTS of servers, possibly with some pretty high-end specs. Also, keep in mind that a lot of the interaction with the database is going to be SELECT queries, just reading out things like character/mob specs, loot tables, etc. There would be quite a bit fewer write operations going on. To handle all the SELECT's you use replication to distribute the load among several different slave read-only DB servers. Write operations would be directed at the master server which then relays those changes to all the slaves.
 

Also, does every windows programmed MMO/Multiplayer  game have to use Winsock?


Every piece of windows software that connects to a network at all uses winsock. Winsock is windows' sockets implementation which drives all socket base communications.
Recycle your old CD's, don't trash them!
Did I help you out?  Feeling generous? I accept tips via Paypal or Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7

#8 Monkuar

Monkuar

    Advanced Member

  • Members
  • PipPipPip
  • 874 posts

Posted 13 September 2013 - 02:35 AM

Okay, I feel a lot more comfortable now about thinking of socket.io and winsocket.  Thank you for such clear explanations Kicken, greatly appreciated.  I know some of these questions are kind of "Herp derp" but I'm just literally laying it all out, I don't care what people think of me anymore. 

 

 

So now that I understand socket's a bit more.  Let me see if I got it right:

 

I refresh a page with socket.io and now I am officially connected to the server.  If the server wants to output "hello world" I could tell the server to do it that via server admininstration right or a command. And it would in essense display it to all users connected?  (Same for software that uses winsock)

 

So being connected doesn't necessarily mean querying unless like you said, having a chat system with a database for storage or logging or whatnot.

 

But a simple global chat system, could just be data that is being sent to all clients connected, but doesn't really need MYSQL Or UPDATES OR any QUERYING because it's just data being outputted to everyone.  So it's more of a bandwidth usage issue in the long run? All that data of people's chat messages being sent across a active connection of 100-200 users would rape bandwidth more than mysql data/querying (since we dont need mysql unless for storage or w/e).

 

This is also why whenever I log out of some MMO's, all my message history is gone.  [But changing channels or going to character selection they stay there] using a temporary session solution most likely?

 

But yeah

 

1 Thought... 

 

For a html 5 game where the server needs to spit out the coordinates of each user on the screen (X,Y, Z) using a 300 milisecond ajax request to update everything would be terrible as in-compared to just using socket.io right? So this technology socket.io is merely the same as winsock? Winsock has been around since what 1999? Why did it take them this long  to release it for browser technology?


Edited by Monkuar, 13 September 2013 - 02:42 AM.

I learn more on this site than I did in K-12 Grade...  (Barand Is a MYSQL King) I dont offer help to anyone anymore because I am the the person who needs help....

"Even if I did learn php 100% I wouldn't even be smart enough to use it..." - monkuar




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com