A network game

hi
I am writing a network game using sockets. But it is slower for an action game.
For chess-type games there is no problem but for games which require
continuous key pressing there is a problem of speed.
how can i speed up network ? any suggestions ?
thanks...

Send only what you need to send. If the users presses multiple keys that is fine, handle these events and then send the end result to the server.
you could also use an advanced technique used in popular game systems (Battle.net for one) and that is the system of prediction. Don't send everything to the server, send just enough so the server can predict what the client has done or is going to do.

Similar Messages

  • Slow network game

    Hi. I am trying to make a multiplayer network game. I got the game to work over a network connection, but there is a delay when I send and receive data and the delay seems to get bigger the longer the program runs. As you can see, I send 20 bytes and this is send about 30 times a second but should this be a problem on a localarea network?
    Here is the code I use for sending and receiving:
    // Class that send data
    import java.io.*;
    import java.net.*;
    public class SendNet {
        int port;
        String group;
        MulticastSocket s;
        public SendNet() {
            System.out.println("Connected SendNet");
            port = 5000;
            group = "230.0.0.1";
            try {
                s = new MulticastSocket();
                System.out.println("Connected!");
            } catch (IOException e) {System.out.println("Error");}
        public void sendData(String up, String down, String left, String right) {
             try
                String st = up+"-"+down+"-"+left+"-"+right+"-";
                System.out.println("Sending: "+st);
                byte[] b = new byte[st.length()];
                b = st.getBytes();
                DatagramPacket pack = new DatagramPacket(b, b.length, InetAddress.getByName(group), port);
                s.send(pack);
            }  catch (IOException e) {}
        public void closeConnection() {
            try {
                s.leaveGroup(InetAddress.getByName(group));
                s.close();
            } catch (IOException e) {}
    // Class that receive data
    import java.net.*;
    import java.io.*;
    public class ReceiveNet {
        int port;
        String group;
        MulticastSocket s;
        String[] move;
        public ReceiveNet() {
            port = 5000;
            group = "230.0.0.1";
            try {
                s = new MulticastSocket(port);
                s.joinGroup(InetAddress.getByName(group));
                System.out.println("Connected!");
            } catch (IOException e) {System.out.println("Error");}
        public String[] getData() {
            byte buffer[] = new byte[20];
            DatagramPacket pack = new DatagramPacket(buffer, buffer.length);
            try
                s.receive(pack);
                String st=new String(pack.getData());
                move = st.split("-");
                System.out.println("Receiving: "+st);
            catch (IOException e) {}
            return move;
        public void closeConnection() {
            try {
                s.leaveGroup(InetAddress.getByName(group));
                s.close();
            } catch (IOException e) {}
    }I've never played around with networking before, so maybe I am doing something wrong, or is it just this form of connection (multicastsocket) that is slow.

    I've never used multicast... but seeing as how nobody replied I'll add a few comments.
    First, I see you specify a port and group in the sender, but it's never used when initializing your connection. Is that a mistake?
    Second, there are a few places where you are creating excess objects which will eventually cause the garbage collector to do some work... which could conceivably slow things down. For example:
    // #1.  You are creating a new String for every invocation of sendData.
    # instead, you could use a StringBuffer, or build your data directly in a byte[]
    String st = up+"-"+down+"-"+left+"-"+right+"-";
    // #2.  You are allocating a byte array and throwing it away.  st.getBytes()
    // returns its own byte array.
    byte[] b = new byte[st.length()];
    b = st.getBytes();
    // change to:
    byte[] b = st.getBytes();
    // #3.  Related to #1, you are creating a new String object with every receive.
    s.receive(pack);
    String st=new String(pack.getData());Not sure whether those are the sources of your slowdown. If you still have trouble, how about providing the code which contains the send/receive loops?

  • Network Game - Sending Over a network question

    I am going to make my first network game.
    I have read tutorials on networking and have designed an echoserver.
    I am however not sure how to pass player moves over the network. I know that it will work the same way as strings
    but how do I pass other players new positions so I can then broadcast changes to all other clients.
    Thanks in advance for any help
    Marc

    you could use serialization, but that can be too big an overhead when you have a lot of players. I would use a simple messaging system, where you send strings over the network in a specific format that you can create on the sending side and unpack on the receiving side. Something like:
    ID;PARAMS
    where ID is a messageId identifying the specific type of message you are sending, and PARAMS is a list of parameters that depend on the message type. For example a movement message could be:
    1;R;40
    This would then mean that the player moved 40 "units" to the Right. A very simple example, of course adapt to your game's situation.
    The advantage of a system like this is that you can string together multiple messages and send them at once. At the receiving end you can just keep parsing messages from the string until there is no more data.
    If you are really tight on bandwidth, then you'll have to start packing bits in binary data in stead. I would go for the messaging system first though, it is the easiest to get working.

  • Network game

    Hello all,
    I'm planning on building a network game for use over the internet. Now I'm working on the network communication but I'm running into difficulties.
    I need a way so that when player 1 on computer 1 tells the game my character is going to move here, this is send over the internet to the server. when the server receives that, it needs to send the move over to player 2 on computer 2.
    I know I can do this by simply broadcasting the move action to all connected players, but this has some difficulties as I have to take into account that player 1 might have a faster internet connection and thus will move faster on his comp then the same character would move on the comp of player 2.
    If you understand what I mean.
    Mark

    well yes, this would probably work with a small number of players. But it would also generate excessive network trafic. It would be much more efficient to have the players send their move (I want to go there with this speed) to the server. Then let the server calculate their path and send their positions to each client every x seconds. All the clients need to do then is have some piece of code to interpolate the trajectory in between the points send by the server.
    This would cut network trafic significantly because only the server is needed to send the intermediate positions to the clients.

  • Network Game - Adding more players

    Hey. i am in the middle of making a network game. I am have a problem with adding new players.
    I am not really sure the best way to do this but what I am doing this now is when a player is first created a
    string is sent to the server and returns with how many clients there are and then sets a client id based on that result.
    In the main class I have a thread running which moves the players that where created (new Players are stored in an arraylist). Whenever a
    player moves it sends its id and current position to the server and the server broadcasts it to all clients.
    So, when this thread runs it gets the id number that it broadcasted and if it is higher than the arraylist of stored players, then I create a new player,
    and add to the arraylist which is then drawn by the paint method.
    When i add a new player, I either add it from another computer or run the program again and connect to the server through port and ip address.
    Is this the correct way to do this because what is happening is that when a second players tried to join new players keep getting added. If any of this is not clear I will try and
    explain it better, sorry
    Thanks in advance for any help given,
    Marc

    if the game is really simple, sure why not. If your game will send a lot of data over the network, then you'll end up in the interesting part of network game programming; how to deal with latency / slow connections. Whole studies have been made out of that subject alone and it is far from easy material to understand, solve and implement.
    I would suggest you check out websites such as gamasutra and gamedev.net for discussions on the topic. A good place to get questions answered is here:
    http://www.gamedev.net/community/forums/showfaq.asp?forum_id=15
    Don't let the fact that it is aimed at C++ scare you away, the information in there mostly applies in general.
    because what is happening is that when a second players tried to join new players keep getting addedYes well that would be a bug in your code. Nobody can help you with that until you provide the code that is misbehaving.

  • Anyone know of a report on the suitability of java for network games?

    Sorry for the long title but couldn't think how to shorten it without losing my point...
    I'm currently needing to write an appriasal for uni and i need some research material that'll help with this subject.
    Though I can find stuff about java and networks and delays there's nothing about games. Any help would be greatly appreciated :)

    I don't know of any specific reports on this, but if you analyse the differences between other areas of networking and game-specific network code and then research whether or not java handles these elements well you should be able to put your own one together fairly easily. Then just post it online and you will suddenly be an authority in the field :)

  • Make java game into networked game

    I have created a 1 player game in java which has 11 classes, to play the game you launch a class which extends JFRAME. Any suggestions on how I can make this game into a two player game over a network, have been looking at trying to change the game into an applet but this loks impossible.

    Ave_beginz wrote:
    i have complete what u say in your post. but it is giving error of reading certificate when i m run our game on different pc over the networked using socket
    plzz tell me how to handle this.
    as my game is chess.
    & also tell me how to make it multiplayer.Don't resurrect old threads from the dead, create a new one. And when you do, be sure to provide details about your problems, as what you are saying now is "Yeah I have this code and it doesn't work." Please put effort into making it possible to help you.

  • Network game communication algorithms... small question

    Just a (hopefully) quick question about getting input from the client side for passing information to a server. At the moment it is set up to take and send the input from the client once the return key is pressed, and send the whole line (with the system.in part). But obviously for a game to be played I am needing the client to send every individual key press from the client. I could try and use the read() method for the bufferedreader, but this returns an int, and I require a string so it can be checked in the server (as I am also going to have a server side representation of the game, as the project is to be investigating lag effects and different solutions to get around online game lag). Or could I use the read() method and use the returned int to find out from that key what was pressed and then change it to the key pressed from the int value returned, or is there a quicker way that doing this check?
    I think there was a method that takes a character array as a parameter and I could somehow set the size to be only 1, so it would send every individual key pressed by the client, then allowing me to send this and display it at the server side? Or am I off on the wrong foot entirely...
    This is the basic code of getting the actual input and then calling the methods which actually sort out writing to the streams elsewhere in the program:
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    s = br.readLine();
    if (s.length() > 0)
    cc.sendMessage(s + "\n");
    Thanks for any help given,
    Cheers

    Hi,
    You could send the KeyEvent object created by the key press event using an ObjectOutputStream or you could just write its code (KeyEvent.getKeyCode()) using DataOutputStream.writeInt().
    If you need the distinction between a press and a release you could write presses as normal key codes and releases as negative key codes.
    In a game I'm making that uses UDP instead of TCP to communicate over the network, since UDP packets aren't guaranteed to get to their destination, whenever a key is pressed or released I send a whole array of integer keyCodes that show which keys are down. This way when a key is released, but the packet indicating the release doesn't get to the server, the server will find out eventually when the next key is pressed/released and a new 'key state' array is sent.

  • Only Spanish audio avaialble on SD feed of NFL Network game

    this is a very odd and specific issue so bear with me. it only happens on SD, HD is fine. on the NFL Network during the Thursday night game, only during the game itself not during commercials, or even when the referee makes an announcement, the audio is in Spanish. i have tried changing the audio option to Spanish and back again and it didn't work. i have FiOS, and given how oddly specific the issue is that may well be important. this is at least the 3rd week in a row i have had this issue. thank you for your help.

    Hi csaff499,
    Your issue has been escalated to a Verizon agent. Before the agent can begin assisting you, they will need to collect further information from you. Please go to your profile page for the forum and look at the top of the middle column where you will find an area titled "My Support Cases". You can reach your profile page by clicking on your name beside your post, or at the top left of this page underneath the title of the board.
    Under "My Support Cases" you will find a link to the private board where you and the agent may exchange information. The title of your post is the link. This should be checked on a frequent basis, as the agent may be waiting for information from you before they can proceed with any actions. To ensure you know when they have responded to you, at the top of your support case there is a drop down menu for support case options. Open that and choose "subscribe". Please keep all correspondence regarding your issue in the private support portal.

  • Network game data transfer

    Suppose one were to make a game, like warcraft 2, where a majority of network data originates by mouse click. Is it possible to only send the mouse click information? Or are the coordinates of the sprites required also?

    Are you saying that you would just send the xy
    coordinates and that would be iterpretted by the
    server or peer? I'm not sure how you will solve the
    synchronization problem.Yes, only the xy mouse coordinates.
    The reason I'm asking is because I was playing a game
    called winbolo (aka bolo for mac users). Every so often
    a message appears on the screen "Network failed - resyncing".
    The keyboard and mouse are disabled until the network problem
    goes away. However, warcraft2 didn't have this problem.
    I'm wondering what techniques they used in warcraft2 data
    transfer.

  • Fifa 13 network game, Origin account

    I bought Fifa 13 on my iphone 5, the game runs pretty well, but when i create an Origin account for network play and go to quick match it give me a message
    "Login failed! Please check your EA Login account details and try again."
    2 month ago when i played fifa 13 on my old ipod touch 4 everything was well, please help me to solve the problem

    sami1958 wrote:
    ... i didnt buy it with my account my friend bought it and he sended it for me ...
    The issue is that it is tied to your friends Apple ID and not yours...
    Anything Downloaded with a Particular Apple ID is tied to that Apple ID and Cannot be Merged or Transferred to a Different Apple ID.

  • Sychronization in network game

    i want to write a simple game which would have multiplayer mode over network.
    (maybe lan or internet) so i have many questions...
    how to write network multi-player game? without serious lagging (not due to network) but a lots of data to transfer?
    how to transfer data? multi-unicast/multicast? what model would be better? server-client?
    how to ensure fluency in the game?
    what technique can i apply to make the game running more smooth?
    any idea?

    Several quick tips for adherance to sound software enginering techniques for any type of multiplayer game design:
    1) depending on the complexity of your project I'd devote at least 10% of your total development time in the design. The better your design, strong oo, data coupling issues, thread manager, bufferStrategy... the easier it will be to actually finish the game. 98% of all games started never get finished. This means having all of your Network communciations in one class or subclassing out extra features that might not be needed for your based network messaging system.
    2. Always thread your communications with higher level priority then your draw method. I've found that setting my network thread to normal and my draw thread to low priority yields far less lag then having them both set to normal priority. The reason for doing this should be evident. Messages are much more important then repainting the display as far as multiplayer games are concerned.
    3. create any new 2d game in Fullscreen Mode and use a bufferStrategy that allows you to flip between offscreen buffers. This will speed up any application written in java tremendously. Repress the repaint call that is normally triggered by the awt. You will be designing your own painting alogrithm so having repaint still active will only slow things down.
    4. Create a separate physics thread from the paint thread. These 2 things need to be separated in order to create fluency in your game. Depending on your actual game desing the physics thread will be responsible for moving things around in your world and handling most of the game communication with other players. The paint thread should only be responsible for drawing the current state of the world. This is probably obvious to most without being said but I've seen a lot of people make this mistake in their initial designs and they updated their game objects just before or after each repaint..
    5. My last point addresses your network traffic issues. There are a lot of techniques out there that can improve your data transfer rate. For example a technique called deadreckoning is often used to reduce the amount of network traffic by 90% or more. Deadreckoning, simply stated, estimates what every other persons objects will be in the physical world since the last message you received. If plausable for your game idea you could send routinue messages to each other player in the game world every 1/2 sec or second and between message communication have your physics thread estimate changes in the world until you receive the next message. Then verify that your estimate were correct/incorrect and reset them if needed.
    Make sure you are only sending data on objects whos modes have changed. If nothing has changed with an object then its data doesn't need to be sent to the other players.
    Hope this helps. you were rather vague about your development so it really isn't possible to suggest one protocal for your network over any other protocal.

  • How much bandwidth should use a network game?

    Hi,
    I'm making a platform game, I think it is very minimal, it is a scrolling level with 20 or 30 elements per time and a refresh every 40ms
    It uses about 1.6MB/minute i think it is so much or not?? how many data should exchange an economical multiplayer game??

    Yeah,
    today i've iproved my algorithm, now it uses only *0.4kB/min* !
    I'm planning to implement something like interpolation of the moving objects (in respect to the main character)
    does exists any "famous" or "official" protocol for client server gaming?

  • New Alternative Serialization classes for Multiplayer Network Games

    Hello Games Developers,
    I've been working on an alternative Serialization technique that attempts to over-come the de-serialization problems of garbage collection and object-finding on the client side.
    I'd like people to try it out and also I need some know-how on HotSpot optimisation, please check out the progress at the Serialization forum at
    http://forum.java.sun.com/thread.jspa?messageID=3990301
    Cheers,
    Keith

    Well, your game is great and all, but the code is really in-depth. We aren't looking for something that complex, just the basics for right now. I have to have something simple to build with right now in order to eventually make something amazing.

  • How to create a turn-based multiplayer online game?

    Hello. This is my first time here. I am familiar with programming games and have been doing so for 20 years. However, I'm completely new to using Java to do so. In the past, I wrote games in BASIC, Blitz, and C++ using DirectX. Being familiar with C/C++, the Java language syntax is not a hurdle for me.
    I've never created a networking game, but I feel that if I tried to create one using one of the programming languages I already know that I would succeed at doing so. (I'm just trying to show that I feel confident in programming with the languages that i know)
    The dilemma here is that someone else would like me to program a turn'based multiplayer game for them in Java.
    I've downloaded the NetBeans 4.1 IDE and uncovered a lot of terms and such that I'm unfamiliar with.
    What I'm looking for from you guys is an overview of what I need to do to achieve my ultimate goal of creating this online game.
    As a reference, I need to create a game very similar to this one:
    http://www.tacticsarena.com/play/
    Click on the "Launch Game: Tactics Arena Online" link to see the game.
    Create a new account to play (accounts are free).
    Upon starting the NetBeans IDE, I found that I could create several different types of projects. I guess first of all, I need to know what kind of project is best suited to make this type of game.
    To name a few, I have to select from:
    Java Application
    Java Class Library (is this an Applet?)
    Web Application
    Enterprise Application
    EJB Module
    Then I guess I would like to know if any of the above projects would be used to make the clients interface or the server side software or both? Or do I need to use some other kind of software/programming language/etc. to create the server side? (As a side note, typically what kind of Operating system would the server be using? I ask because I may set one up myself for testing purposes.)
    Somewhere I came upon the term 'Servlet'. Is this some kind of Java server application? Do I need/want to be using this?
    As you can see, I'm very lost at where to begin. I'm not at all unfamiliar with programming. I'm just unfamiliar with Java.
    WolRon

    Hi WolRon
    I am in the process of learning Java myself and from what i have read, you have a long road ahead of you!
    To start this Project the following will be essential for you to know:
    Applets - if this is going to an online game
    Multiple Threads - for the Server side
    Swing - for the GUI on both sides
    AWT - help work with the user input (mouseListeners, buttonListeners, etc)
    And knowledge of a database.
    those are the most obvious things that you will need to understand.
    I strongly suggest buying a Java book from which you need to start at the beginning. Although the concept of OOP is the same through most languages Java has terms - as do all languages- that will be different from the other languages. Starting at the beginning will be beneficial to your Java coding future.
    Good luck.

Maybe you are looking for

  • Can i use one interface to load data into 2 different tables

    Hi Folks, Can i use one interface to load data into 2 different tables(same schema or different schemas) from one source table with same structure ? Please give me advice Thanks Raj Edited by: user11410176 on Oct 21, 2009 9:55 AM

  • How can i transfer my old songs

    how can i get my music off my old computer and on my new one i dont know if it makes a difference but the old computer is xp and my new one is vista

  • How to move full repair data from DSO1 (soruce) to DSO2(target)?

    Hello experts, I doing full repair for po in first level ods, Do i have to move this data from first level ods to second leve ods? or the daily nightly delta from first leve ods to second level ods will take care of it? If i have to load the data fro

  • Migrating from SQL Server to Oracle 8i

    Hi all :), I am trying to migrate from SQL Server to Oracle 9i. I am using the Migration Workbench. Everything goes fine during Capturing phase, but while creating Oracle model the Workbench just hangs at "Mapping Tablespaces" for over three hours. (

  • Improving timing and solving tempo issues in Logic

    Hello, I was reading something about the beat mapping in user manual and also I was trying to improve timing of my drums recording but with no result. Is beat mapping the right tool for doing this and if so, what are the right steps to do it? Please,