Network Simulator

This is a discussion on Network Simulator within the C Programming forums, part of the General Programming Boards category; Hi, I am looking to develop a network simulator in C. A simple game involving avatars would be run on ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    6

    Network Simulator

    Hi,
    I am looking to develop a network simulator in C. A simple game involving avatars would be run on the virtual network. It will work by a virtual client generating a move for an avatar and sending the move to its virtual server. The virtual server will either accept or reject the move, depending on the current game state. A delay will be imposed between the client and server. The simulator will have a number of virtual servers, and a number of virtual clients on each virtual server.

    My question how am I able to simutainesly have the virtual clients generating moves for its avatars, as well as the virutal servers processing its clients moves and making decisions.

    Thanks .

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    You'll want to look at threading. Your program is a process running under the Operating System, and the Operating System can have several processes running at the same time sharing CPU time. The same concept is applied to programs, where a program can have several threads.

    How exactly you do this is different on every system, so you could either google, or let us know what OS you're using and we'll make some recommendations. Right off the bat I'll tell you about SDL (www.libsdl.org). It's mainly a graphics-sound library designed for creating games for multiple target platforms, but it can handle threading too. If you're going to need a graphics API anyway, why not use this one?

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    If I understand you correctly then you might not need everything to be done "silitineously".
    A typical game loop looks something like this.
    Code:
    while(StillInGame)
    {
       ProcessInput();
       UpdateObjects();
       UpdateScreen();
    }
    Each time thru the loop would be one frame, the user sees all objects apearing to move at once. In reality there postions aren't updated at exacly the same time but because it's all done inbetween frames it isn't noticable.

  4. #4
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    If he's simulating a network, he may want to have the effect (and it very well may be noticeable) of having one object make decisions and have them rendered while another object is still making it's decision.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Quote Originally Posted by sean_mackrory
    If he's simulating a network, he may want to have the effect (and it very well may be noticeable) of having one object make decisions and have them rendered while another object is still making it's decision.
    That can still be done without threading. If each object is only allowed to do a certain amount of virtual operations per frame one could make decisions while another is waiting on the result of some operation.
    I think it depends on weather he's writing a simulator or an emulator which can link in with a real network connection.

  6. #6
    Registered User
    Join Date
    Apr 2005
    Posts
    6
    Quote Originally Posted by Quantum1024
    That can still be done without threading. If each object is only allowed to do a certain amount of virtual operations per frame one could make decisions while another is waiting on the result of some operation.
    I think it depends on weather he's writing a simulator or an emulator which can link in with a real network connection.
    It is only a simulator I am writing. The point of my program is to study the effects of lag in a online game and to introduce some methods of lag compensation.

    Since my virtual game does not need to be run in real time, I was thinking of using somthing similar to this:

    Code:
    while(StillInGame)
    {
       ProcessInput();
       UpdateObjects();
       UpdateScreen();
    }
    But the problem is there will be possible hundreds of Clients playing the game. When a move is generated for a particular client (i.e avatar), this client must send a message through a delay function to its server. The server will verify (or reject) the move and sends updates to all the other servers via a delay as well.
    Now while the server is processing its clients request and sending updates to the other servers, how do I make the client function generate a move for another avatar?

    Would I need some sort of scheduling function which switches between the server and client functions so It seems everything is running in parallel?

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    You could have a command structure that contains the delay in simulation cycles
    Code:
    struct Command
    {
       int delay;
       ...
    };
    When a server first receives a command it could add it to its list of commands to be processed and subtract 1 from the delay each cycle. When the delay reaches a certain value you could report that the server received the command and when it reaches zero Take some action(send a command or update)l. Each cycle loop thru each server's command list and subtract 1 from the delay value or report that the command is complete.
    Same for the client function, loop thru the client function's list of commands to be sent and commands to be received.
    So at the end of each cycle all server and client messages are either processed or have had there delay value decreased.
    Hope this helps.
    Last edited by Quantum1024; 04-05-2005 at 01:17 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 3D Network Analysis Tool
    By durban in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 11-08-2005, 06:33 PM
  2. Need help with easy Network setup
    By the dead tree in forum Tech Board
    Replies: 9
    Last Post: 04-08-2005, 08:44 PM
  3. destroywindow() problem
    By algi in forum Windows Programming
    Replies: 6
    Last Post: 03-27-2005, 11:40 PM
  4. network problems
    By lucy in forum Tech Board
    Replies: 6
    Last Post: 01-01-2003, 03:33 PM
  5. WinXP Network Connections pop-up
    By DavidP in forum Tech Board
    Replies: 1
    Last Post: 10-02-2002, 06:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21