Server Traffic Regulation

Hi, I just need a good way to regulate the IO of a server im making. The server needs to send the players, monster, items, and objects in each players screen very frequently. This is what i have so far. If there is anything i should add could you please post, as i think the messages on the client or server are piling up on eachother, so it takes a while before the user can see the affect of what it has done.

// Server

import java.util.Enumeration;

publicclass ServerThreadimplements Runnable{

Server server;

ServerThread(Server t_server){

server = t_server;

}

publicvoid run(){

while(true){

runReturn();

}

}

publicvoid runReturn(){

Action action;

Player player;

// All players inputs

for(Enumeration e = server.players.elements() ; e.hasMoreElements() ; ){

player = (Player) e.nextElement();

action = player.nextAction();

player.cleanUp();

if(action !=null){

try{

action.doIt();

action =null;

}catch(Exception ee){

System.out.println("Error in doIt");

ee.printStackTrace();

}

}

else

{

player.idle++;

if(player.idle >= 30000){

player.disconnect("Idle");

}

}

}

ItemSpawn is;

for(Enumeration e = server.itemspawns.elements(); e.hasMoreElements() ; ){

is = (ItemSpawn) e.nextElement();

if(is.spawn){

is.addToSpawn();

}

}

// All output is asked for by the client.

try{

Thread.sleep(10);

}catch(InterruptedException e){

}

}

}

// What the abstract action class looks like:

publicabstractclass Action{

Server server;

Client client;

Player player;

publicvoid setPlayer(Player t_pl){

player = t_pl;

}

publicvoid setClient(Client t_client){

client = t_client;

}

publicvoid setServer(Server t_server){

server = t_server;

}

publicabstractvoid doIt();

}

// A class that extends Action

import java.io.Serializable;

import java.sql.*;

publicclass Moveextends Actionimplements Serializable{

private String dir;

public Move(String t_dir){

dir = t_dir;

}

publicvoid doIt(){

int i_dir = 0;

int x = player.getX();

int y = player.getY();

if(dir.equals("Up")) i_dir = 1;

if(dir.equals("Down")) i_dir = 2;

if(dir.equals("Left")) i_dir = 3;

if(dir.equals("Right")) i_dir = 4;

switch(i_dir){

case 1:

if(!server.checkSolid(x,y-1)){

player.setY(y - 1);

try{

Statement stmt = server.conn.createStatement();

stmt.execute("UPDATE Login SET Y=" + player.getY() +" WHERE UserId="+player.userid);

}catch(SQLException e){

e.printStackTrace();

}

}

break;

case 2:

if(!server.checkSolid(x,y+1)){

player.setY(y + 1);

try{

Statement stmt = server.conn.createStatement();

stmt.execute("UPDATE Login SET Y=" + player.getY() +" WHERE UserId="+player.userid);

}catch(SQLException e){

e.printStackTrace();

}

}

break;

case 3:

if(!server.checkSolid(x-1,y)){

player.setX(x - 1);

try{

Statement stmt = server.conn.createStatement();

stmt.execute("UPDATE Login SET X=" + player.getX() +" WHERE UserId="+player.userid);

}catch(SQLException e){

e.printStackTrace();

}

}

break;

case 4:

if(!server.checkSolid(x+1,y)){

player.setX(x + 1);

try{

Statement stmt = server.conn.createStatement();

stmt.execute("UPDATE Login SET X=" + player.getX() +" WHERE UserId="+player.userid);

}catch(SQLException e){

e.printStackTrace();

}

}

break;

}

}

}

Again thanks for ur help guys :)

EDIT:

All the stuff that is sent to the client is asked by the client.

here is an example:

import java.io.Serializable;

publicclass AskUpdateUserextends Actionimplements Serializable{

publicvoid doIt(){

player.send(new UpdateUser(player));

}

}

[9364 byte] By [Futurisdom_Developera] at [2007-10-3 3:10:49]
# 1
Guys id really appreciate some suggestions to this problem.Thanks
Futurisdom_Developera at 2007-7-14 21:01:37 > top of Java-index,Java Essentials,Java Programming...
# 2
I assume this is the best way to do it then? Please post a response.Thanks in advanced
Futurisdom_Developera at 2007-7-14 21:01:37 > top of Java-index,Java Essentials,Java Programming...