Multiplayer game programming - Code of a basic server

I'm a beginner in multiplayer game programming and I'm looking for the code of a basic server for a multiplayer game. I don't mind which kind of game (I mean: chess, ping-pong, battlenet...) The important thing is the code pattern abnd the server structure.
Could anyone help me?

If you want to have a look at a generic multi-threaded server, check out the Java networking tutorial.. there's a basic example server that responds to a "Knock knock, who's there?" conversation.. you can start off with it..
Of course it's not a game server but you could try sticking in a game engine to maintain the game world and change the user sessions to a proper game protocol.. e.g. sending key strokes or joystick movements. You could also get the server to send player and enemy positions etc...
Good luck!

Similar Messages

  • Multiplayer game: how to synchronize client and server

    Hi there, I'm wondering how to synchronzie client's and server's frame number?
    I have a multiplayer spaceship(2D) game running at constant 30 FPS, since I use "frame number" to determine if a packet is too late or not, so I would like to have server and client both start frame 1 at the same time, but I have no idea how to do so, can anyone give me a hint?
    well, if you want more details(may not be too much relevant to my problem, but any way, for anyone who interested):
    I use UDP(my teammate implemented a TCP version, it's working but TCP is just way too stupid, lagging and some unknown problems produce very funny result). So far, on client side, input(key strokes) is sent via network immediately, but processed 2 frames later locally. So on lan, server will likely get the packet before it's time to process it, thus solve the packet delay problem a little bit).
    Example: If user pressed fire button at frame 5, it's sent immediately to server, then at frame 7, client engine processes this "fire" event, and likely, server will get this packet at frame 6 or 7, then it can just processes it in time as well.
    So there's a problem, server and client must both running the same frame number at the same time(maybe not exact, but gotta be very close).
    By the way, I need some suggestions implementing the server, my brain hurts just thinking about it, I hope I will never have to code network stuff again: Server runs at 30FPS(but only broadcast game state at 6FPS), it just sit there between frame 1~4, get all packets and store them, then between frame 4~5, processes all the packets recieved, then broadcast the result(game state), client recieves it, will treat this game state as "correct game state for frame 5". I use this way because it solves packet delay and out of order packet to some extend.
    However, say, if server broadcasts the game state for frame 5 at frame 5, then client is likely to recieve it at frame 7 or even later, how can client use it?
    So, together, if you have suggestion or solution for my server and client implementation, please let me know, thanks heaps. I'm in quite a desperation at the moment.
    P.S: I also posted this synchronizing problem at the socket programming forum, hope you guys (and girls) dont mind, since this is a place talking about game, that is a place talking about network, so I thought might be good to have suggestions from people in different programming area.

    Why does the client need to have the same frame number as the server? I think a good way to do it would be as follows:
    - Client sends all of the user's commands to the server (i.e. accellerate left, accellerate right, start firing, etc).
    - Server processes these to update game state and every so often sends updates to the clients, saying something like "at frame 7, user X is at (10, 10) and user Y is at (20,20) and firing south".
    - Clients process all updates from the server, as long as it hasn't seen any update from a later time yet. So if it recieves the update from time 10 before the update from time 9, it only does the one from time 10. It tries to move things smoothly, taking into average time between updates (if there are 100 ms between updates and on the next frame, user X should move 10 units, then move 1 unit every 10 ms).
    By the way, it is possible to use TCP in games. Most MMORPG games use it. I don't know whether it's fast enough for a spaceship game, but it might be worth trying to fix the code you have. Try to keep packets small (use bytes for event type codes, player numbers, etc), group multiple events into one packet if they are all available at the same time, flush() the output stream as soon as you send one, and don't use a buffered stream or reader when reading them.

  • Error while unpacking program, code 2 Win Server 2008

    When trying to run an application (specifically "Image for Windows" by Terabyte Unlimited), I receive the following error message:
    "Error while unpacking program, code 2. Please report to author."
    I have seen numerous hits for this error while searching Google and nearly all of them point to an issue with a Windows Update. However, it's nearly always for Windows Vista.
    I'm getting this error Windows Server 2008.
    I have another machine running Windows Server 2008 that does not have this issue.
    Is this an issue with a particular Windows Update or could something else be the cause?

    C:\Users\administrator>net helpmsg 2
    returns with
    The system cannot find the file specified.
    The package may be corrupt.
    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows]
    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.

  • About server in game programming

    hi,
    from what i know, we need a web server like tomcat or blazix to make other people can access our web. but my problem is like this..... i develop a game programming that need a server to control the player, so that mean now i have 2 server...... but when people acces my web, they cannot connect with my game server, so they cannot play the game..... so what should i do to make people can access my web and play the game?

    I presume this is about how to have a game run in the background on the server, outside of the web requests the user made to get to the game in the first place.
    What it comes down to is, you need some way to get the data back, asynchronously or pseudo-asynchronously. You have a few options...
    (1) Run a process on the server separate to the web server, which opens the game server socket, and does all the game stuff. Simplest solution.
    (2) Make a little servlet which initialises when your webapp starts up, and the init() method starts a thread, which opens the game server socket, and does all the game stuff. A little harder, but better because it will work even if you don't have a shell to the web server (e.g. if you're on a hosting provider who has given you just an FTP.)
    (3) Make a little servlet to perform the actual game functions, and either poll at regular intervals or have the servlet itself send the data back as a continuous stream. I personally like this solution the best, and it doesn't require a thread to sit there on the server wasting a thread, but it does make a single HTTP request last for a rather long time and also proxies can screw around with the data.
    Hope this helped somehow...

  • Multiplayer game, different rooms.

    I am in the midst of coding a multiplayer card game. Right now, to make things simple, I limit myself to code for 3 players for one room. The clients call functions in the server and vice versa. Functions such as player's turn, shuffling cards, etc.
    So what happens if there's more than 1 room? Won't the data from the different rooms get mixed up with one another in the server side, since everything will be happening in just 1 server and on the same function?
    I am abit confuse on this part. Can someone enlighten me on how different rooms work in a multiplayer game? How do I make sure the data don't get messed up?

    wether you code it by adding a parameter in your function calls to tell wich room is concerned, wether you use different instances of the same application. each room access will use different urls (but you can link them to a common entry point where you relocate players when they start a game).
    check the FMS documentation about this subject, that might saves you loads of programming.
    IFZen

  • Multiplayer game applet

    Hi,
    I'm currently developping a multiplayer game as a personnal project. I thought of applet as an ideal mean of making this available easily from anywhere.
    I designed the game, developped the core game code, and made a quick GUI. Then came the time to plug that together with a communication protocol.
    Applets can only connect to the server it was downloaded from. No problem there, I can run the game server on the http server (the DB's there anyway).
    I thought about RMI, but my first tests, although totally successful on my LAN, proved a nightmare when crossing the little familiar boundaries of my home network.
    So I was wondering about writing my communication code using sockets instead and controlling my own game data frames.
    So my question is, from your experience, what would you do to communicate between an applet and a server? RMI or sockets? Is there anything else which I haven't considered?
    From what I read, RMI would require me to make the user install a policy file on their local disk, which is out of question.
    Most communications will be initiated by the client, hence why I chose RMI, but I would have ideally to make some communications on the other side. Sockets would allow this two way communication, but from what I understood, it wouldn't work using RMI because this would mean for the applet to start a rmiregistry and listen on some ports?
    I would really appreciate your input on which way I should head for my communication layer, which pitfalls awaits me and where I can get more details from similar projects.
    Thanks!

    Thanks for your input.
    My problem is that I'm an utopist and want my game accessible to the most people possible. Everybody has a browser, but not everyone has web-start.
    Having to install web-start or a policy file on their system might turn off some potential players from giving it a try. And in some environment, it may be simply impossible (my university's network admin won't let me install web-start, and this is the case in many other places for sure).
    The sandbox is not a problem to me since I can run the game server from the http server and only connect to the server the applet was served from.

  • Multiplayer Game (JSP, Servlets)

    I have been programming a Multiplayer game for about a year now.
    It is simmilar to the popular Tower Defense games but I can't give you all the details.
    Would anyone be able to refer me to some examples that include
    Login features (connecting to a database or something)
    two players play a simple game, or chat or something, just to get me started.
    Thanks!
    ~Matt

    A multiplayer TD game? Sounds interesting. Are you planning on sending the game communication through a server, or direct connect to the other player? Are you looking for a Yahoo style setup when you join a chatroom and play from there?
    There is a program on SourceForge.net called JOGRE (Java Online Gaming Realtime Engine). It appears to have many of the features that you would expect on Yahoo, but their demo server is not running, so I could not try it out. It may be what you are looking for. The network communication is all in XML though, I wonder if XML is too network intensive for a multiplayer TD game...

  • Flash issue's with online multiplayer game's

    I play alot of online multiplayer game's, i spend thousand's of dollars a year in playing, I update my computer everytime something new come's out. This is the first time i found a game flash based i wasn't to impressed with, Game i am talking about is wartune.com. when u aint around alot of people its fine, minute u get around alot of people it slows down. i have tried diffrent brower's and also diffrent settings as recommended on ur site. What i would like to see is flash be more friendly to less lag cause by flash, or even frames per second option available so a user can see what is going on. When flash aint lagged down it work's great, but need some more settings to boost the performance of it, Hardware acceleration almost does minnunim to nothing, i have 32 gigs of ram, duel processor's, duel video card's.  my system is very welll mainted as i don't do much but gaming on it. Give us some options to improve the respones time with flash, or even let use use are video cards more effecicantly with flash, Also just a not some complain the high useage of memory during online gaming have to refresh webpage alot to speed back up, Speaking to gaming sites doesnt seem to help, Only way i truely believe they will change is when they have to change, So im coming to u as a customer of alot of flash stuff, force them to do something, do ur 12.0 flash update with some added fetures for use gamers, give us a option to speed up are flash, I will state that theres other programs out there that when ran with flash it make's it go super smooth, but ur not allowed to run second programs during gaming, but if it smooths it out tremdously maybe that be something for u to look into? Any question's feel free to msg me back.

    You can buy top PC but this will not fix issues that made game developer. Yes, game developer. Not Flash Player developer. First of all you need to ping your game server.
    On PC in Windows you need to run in cmd this string: ping wartune.com but this is may not show real IP of game servers. I can't enter to wartune because there is error 404 - page don't found. So you need to know their servers IP and try to ping them. All ping that shows more 50ms will cause a lags. Ping it's timeframe for delivery data  between your PC internet and wartune sever.
    PS. my ping showed 192ms. So if game have the same server as hosted web site - I must see lags due big ping.

  • RTMFP: Multiplayer games

    Hi.
    I have a lot of flash games and was always told that for multiplayer you needed to use things like smartfox server and other software.
    I have just read about the RTMFP which was introduced in 10.0 and updated in 10.1 - does this mean that programming multiplayer has just got easy or have I misread the article.

    RTMFP means that you are capable of building P2P multiplayer flash games that can be low-latency enough for realtime multiplayer games.
    You'll still need to use a central RTMFP rendevous server like Cirrus, Flash Media Server, or the Open Source solutions (like Cumulus or ArcusNode) to establish the "handshake" that will allow clients to directly connect to each other over UDP and RTMFP.
    In terms of difficulty it can actually be slightly more difficult just in the sense that you'll need to build some type of "lobby" service to matchmake players that want to create a game, also if you want to follow the P2P networking model that games like modern warfare uses you'll need some way to establish one of the RTMFP clients as the "host"/"server" so that you'll be able to run some type of consistent simulation (and possibly develop a fallback system in case the "host" drops and you need to promote another peer to be the host).
    In terms of costing less to get a multiplayer game up and running RTMFP potentially provides that because you won't require a central server to run the games through only to provide the initial matchmaking and RTMFP rendevous.

  • How to create a multiplayer game for steam using flash/flex?

    Hi guys,
    We've got a multiplayer game ready to go. Currently it is not multiplayer, but we'd like to get it to a stage where it can be played over the steam network by users of steam and owners of steam games.
    We'd like to if anyone could briefly give us a breakdown of how to get out game up on steam and available for multiplayer?
    Does steam host servers, and can we utilise a steam server to transfer data between players or would we have to run our own server?
    Currently were using flash builder to publish via adobe air to a windows desktop exe. Can anyone briefly explain how - once a player has downloaded the game from steam we can connect two players? Does anyone know how to use actionscript 3 to access steam network?
    Anyone have any experience developing multiplayer turn based game for steam using flash /actionscript 3 /adobe air?
    Thanks for your help in advance,
    i

    You would want to use the SteamWorks API, which is available from Steam as a C++ library, but there is most likely an Adobe Native Extension (ANE) that would allow you to use the library in AS3.
    I've never used SteamWorks but it seems to support peer-2-peer matchmaking (in other words, you wouldn't even need your own server, I think.)
    SteamWorks API:
    https://partner.steamgames.com/documentation/api
    Search results for "SteamWorks AIR ANE":
    https://www.google.com/search?q=steamworks+air+ane
    -Aaron

  • Authorization group - to restrict other users to not see the program code

    Hi,
    I have developed report program. Is it possible to restrict the other users to don't see the program code.
    Thanks in advance.
    Regards,
    Eswar

    Eswar:
    SAP does not allow you to restrict access to your report programs. Anybody with the right autorizations can see your programs.
    There are some tricks to achieve someting like that. Tricks consists basically in write your code without enter between lines. I think there are no effective way in SAP or ABAP to protect programs source code from curious eyes.
    Ex.:
    REPORT ztest. TABLES: ztable. DATA: g_var1...
    Regards.
    Rafael Rojas.

  • Applet Game Programming - player movement

    HI Java Experts,
    I have a very simple question applet game programming - jdk 1.02.
    Let's say you have a player on the applet window. He can move right and left.
    Naturally you have an image representing the player. When the player moves left you present an image loop with him running left. And vice versa for running right.
    Of course when he stops moving you just want to show a still image.
    What do you guys feel is the best technique for that situation ?
    Stephen

    Hi Thanks for the advice.
    I'm under the impression that if I used jdk1.4
    everybody who wanted to play the game would have to go
    through the trouble of downloading something . If
    that is so, then i would like to stick with 1.02 to
    have the widest possible audience.Use Java Web Start to deploy it as an application instead of an Applet. If your program is really cool, people will download the JDK 1.4 to use it. Then we will have more java users in the world :)
    By the way i have a URL perhaps someone could look > at the source code and give additional suggestions
    you can make sonic the hedge hog run and jump
    http://www.swebdev.com/Adventure.html
    That code has some good points. I like the nice object oriented flow of it. However, the way he sets up the Thread is all wrong. He uses yield and sleep, you would want to set up this using wait() and notifyAll() calls if you want to make it more interesting.
    Right now i'm trying to address the issue of how to
    reverse the image for when the player is running the
    opposite way -- ? perhaps a separate thread in 1.02
    might be an answer? I would be glad to hear all kinds
    of suggestions on the sample code seen thereYou shouldn't need a separate thread just to reverse the image. If your little guy is already in his own thread, just switch the image that is displayed when the player hits the opposite direction key.
    Think of threads like puppets, and you are the puppet master. Your little guys is a puppet, so he should be in his own thread. You can make him do whatever you want from your thread (the master) by pulling strings (changing globals, and message passing)
    Wow... Thats a really good analogy... I just thought that up :)

  • J2Me game programming plz help

    Helo everyone,
    I am working in j2me game programming plz if
    any one know how make image as small as possible
    in our game program.?
    I am using *.png format of image which is working well
    in game but my game size is very big so plz help me to get
    out of this problem
    Thank u
    Aman Gautam

    I solved the same problem by using indexed color images instead of true color.
    So, for example, if you have a colorful background you can convert it to a 256 color image.
    Depending on your specific image and the devices you'll see it on you may or may not notice the difference, but the file size is generally smaller.
    Then you can push further for smaller elements, like, say, a moving object like a pointer or a starship, you can reduce it to 60 or 30 colors, or even less.
    Another technique is to use tiles to build up the background instead of big images. With MIDP2.0 there's the TiledLayer, but you can implement the same with some code also on MIDP1.0 if backward compatibility is of concern.

  • About game programming.. please....help

    How to define game map for java midlet
         If I see the rpg game, it have default map. I want to know how to translate it to code
         in midlet? The map will be existed image or dynamicly generated?
         Like Prince of Persia Midlet version, I wonder how to generate the environment?
         Is it pixel generated or immutable image?
    detect collision
         SO if the map is image and the sprite game is draw over the map, how can we detect the
         collision?
         Please hellp me.... because I want to be game programmer for midlet but I
         didn't know about game programming before

    to write a small game in midl is already a hard work. to make a big one, take a look of a team of programers.
    about maping, there is no such thing. wire every thing by yourself. by books or read tutorials.
    as i already said. no easy task.
    but keep on trying. if you need some help write me a mail.
    [email protected]
    jeliel
    (sebastian)

  • Tool to help you write multiplayer games

    I have created a tool to help Flash developers interested in
    writing multiplayer games. It should take care of a lot of the
    details of communicating with sockets, enabling you to focus on
    your game code. Advanced Actionscript and PHP coding skills are
    required:
    http://flashmog.net

    Apps have reviews.  Check the reviews from the public and get a sense of quality from them.

Maybe you are looking for

  • How do I search for a value in an Excel sheet using ActixeX

    I am already accessing my excel sheets however I need to be able to search the sheet for a certain value and return the row/cell location. Is there an activeX control that can do this?

  • How can I quickly add text to a jpeg?

    Hi folks, I'd love to be able to just click on a jpeg and then add text to it. Preview Help says I can add text to an image by clicking Annotate and then Text, but I can't get anything to work. What am I doing wrong? Can anyone recommend a quick and

  • Cant create adobe files from multiple excel or word files

    This is the first time I have placed anything on this forum so please forgive me if I am in the wrong p lace.  I have been frustrated by an error message I get when I try to convert multiple excel files or word files to PDF.  The files exist on a net

  • How to access purchased iTunes movies/TV episodes without loading large amounts of data on devices

    II have a quick question and I apologize if it has already been addressed in another forum & I had not found it yet (if so please link me to that forum) but I was looking for a way to stream movies and TV episodes that I have purchased on our iTunes

  • AD RMS offline content

    As per this link http://blogs.technet.com/b/rms/archive/2012/04/16/accessing-protected-content-offline-and-content-pre-licensing.aspx we can access and protect the content offiline.However if i bring the RMS server down users are not able to protect