Take the 2-minute tour ×
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

closed as off-topic by Byte56 Mar 22 at 14:58

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about "how to get started," "what to learn next," or "which technology to use" are discussion-oriented questions which involve answers that are either based on opinion, or which are all equally valid. Those kinds of questions are outside the scope of this site. Visit our help center for more information." – Byte56
If this question can be reworded to fit the rules in the help center, please edit the question.

5  
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. –  jco Dec 28 '11 at 18:04
    
-2 and 7 favorites lol –  jhocking May 28 '13 at 15:04

1 Answer 1

up vote 38 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
    
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
    
"Each connection gets its own thread for the messaging" Note that this is the easy way to do it but it doesn't scale well at all. If you expect more connections per server than cores available on the hardware, you'd better invest in learning about task-based concurrency (or thread-pools if you prefer). –  Klaim May 28 '13 at 14:32
1  
I'de venture to bet that anyone reading this isn't in a place where scale matters. Simplicity and completing something are a lot more important –  brandon Feb 4 at 20:41

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