Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am developing a multi-player on-line game.

I just started coding the server but I have no idea how to do it. Do I have to use threads ?

And if i do, do I need one thread for every client?

Knowing that I am using UDP, can I use multiple sockets in different threads to send packets on the same port?

edit:

server does:

-listen for client connections

-when a client connects:

    -update files (send new files to the client)

    -retrieve data from database

    -loop to retrieve and update live data

-when client disconnects:

    -update data in database
share|improve this question
2  
Not strictly an answer, but: you should strongly consider starting with a working MMO server framework, and then altering it to your specific needs… – BRPocock Dec 28 '11 at 16:28
2  
If you have no idea, use SmartFoxServer or something – Nevermind Dec 28 '11 at 17:48
1  
I just save all "Player" objects in an array and I'm doing pretty fine... A "Player" object has a property called "connection" trough which you can communicate. – Yannbane Dec 28 '11 at 18:04

1 Answer

up vote 26 down vote accepted

I may be wrong, but your question makes it seem like you are missing a lot of knowledge in order to successfully write an MMO server. I know this message will likely fall on deaf ears because I was in your position when I started programming.

My answer: If I were you I would start smaller. If you want to learn to write an MMO server I would do the following.

  • Write a TCP based p2p chat client.
  • Extend that chat client to work with NAT routers
  • Extend the chat client to have a central server that authenticates and stores message history
  • Extend it to have a secure handshake with the server to verify the client software and server software/location
  • Write a high level architecture of what you would want your MMO server to be
  • Read some articles on MMO server architectures
  • Start expanding your high level architecture into more and more detail
  • Write essential user stories for your architecture
  • start implementing your server

The answer you probably want:

  • Write a thread for the listener to accept incoming connections using TCP
  • Once the player is connected, use TCP for chat messages and sector changes
  • Use UDP for in-sector movement
  • Each connection gets its own thread for the messaging
  • UDP can be implemented with threads (if you really want) but I would probably use some sort of queue on one thread that accepts movement messages. Or spread it out depending on how many connections you get.
share|improve this answer
right away, one moment please. – Baccari Dec 28 '11 at 15:06
This should really be a comment. – Zolomon Dec 28 '11 at 15:21
I don't get some of the points, but i will go through all of them one by one to understand them and do whatever is necessary to finish the server. – Baccari Dec 28 '11 at 15:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.