problem in network , (sending game data)
i was developing a network game which allowed multiple player. so... at first in my testing stage, i test the program in one computer( 2 program connect in 1 computer) and it doesn't have any problems. when i test the program in network enviroment, the movement of the character are not same in other networked computer. the character in the server are moving, but in the client computer, the character does not move. is this because the data are lost? i was using socket(), which is tcp/ip
[498 byte] By [
ckminga] at [2007-9-28 2:45:00]

after i try for a few times.. i discover that sometime the program works fine. but juz for a certain duration. after certain duration, the client connection hang. the error was something 2 do with data format as show on the dos prompt. maybe it have something 2 do with my data protocol? i'll show my coding...
//....server connection........
public void run() {
try {
ss = new ServerSocket(4444);
menu.jLabel5.setText("ip : " +ss.getInetAddress().getLocalHost());
while(true) {
clients.add(new sThread(ss.accept(), this, playerName));
add_monster();
add_professor();
}
}
catch(Exception e) { e.printStackTrace(); }
}
//****************RECEIVED DATA FROM CLIENT********************
public void msgReceived(String s, Thread t) {
sThread tempThread;
//..................send data to all client...................
for(int i=0; i<clients.size(); i++) {
tempThread = (sThread) clients.get(i);
tempThread.sendData(s);
}
//..................add client name into list ...................
if(s.charAt(0)=='-') {
playerName.add(s);
playerVec.add(new player(s, playerVec.size()));
list.setListData(playerName);
}
//....................move selected player........................
if(s.charAt(0)=='p') {
player tempPlayer = (player)playerVec.get(Integer.parseInt(s.substring(1,2)));
tempPlayer.move(Integer.parseInt(s.substring(2,5)),Integer.parseInt(s.substring(5,8)));
}
//....................move selected monster.......................
if(s.charAt(0)=='m') {
sprite tempMonster = (sprite)monsterVec.get(Integer.parseInt(s.substring(1,2)));
tempMonster.move(Integer.parseInt(s.substring(2,5)),Integer.parseInt(s.substring(5,8)));
}
//...................move selected professor..................
if(s.charAt(0)=='r') {
sprite tempProf = (sprite)professorVec.get(Integer.parseInt(s.substring(1,2)));
tempProf.move(Integer.parseInt(s.substring(2,5)),Integer.parseInt(s.substring(5,8)));
}
}
//**********CLIENT PART**************
public void run() {
try {
socket = new Socket(ipStr, 4444);
output = new ObjectOutputStream(socket.getOutputStream());
output.flush();
input = new ObjectInputStream(socket.getInputStream());
String inputData;
boolean endCount = true;
sendData("-" +name);
//******************RECEIVE DATA FROM SERVER***************
while((inputData = (String)input.readObject()) != null) {
if(inputData.charAt(0)=='-') {
playerVec.add(new player(inputData, playerVec.size()));
add_monster();
add_professor();
playerName.add(inputData);
if(endCount)
clientNo++;
if(inputData.equals("-" +name))
endCount = false;
list.setListData(playerName);
}
//..............if server initiate start game................
if(inputData.equals("startGame")) {
openGame();
}
//....................move player...................
if(inputData.charAt(0)=='p'){
String s = inputData;
player tempPlayer = (player)playerVec.get(Integer.parseInt(s.substring(1,2)));
tempPlayer.move(Integer.parseInt(s.substring(2,5)),Integer.parseInt(s.substring(5,8)));
}
//........................move monster.....................
if(inputData.charAt(0)=='m') {
String s = inputData;
sprite tempMonster = (sprite)monsterVec.get(Integer.parseInt(s.substring(1,2)));
tempMonster.move(Integer.parseInt(s.substring(2,5)),Integer.parseInt(s.substring(5,8)));
}
//......................move professor....................
if(inputData.charAt(0)=='r') {
String s = inputData;
sprite tempProf = (sprite)professorVec.get(Integer.parseInt(s.substring(1,2)));
tempProf.move(Integer.parseInt(s.substring(2,5)),Integer.parseInt(s.substring(5,8)));
}
}
//*****************RECEIVING SERVER CODE ENDS HERE**********
}
catch(IOException cnfex) { cnfex.printStackTrace(); }
catch(ClassNotFoundException cnfex) { cnfex.printStackTrace(); }
}
//....function to send data to server........
public static void sendData(String data) {
try {
output.writeObject(data);
output.flush();
}
catch(IOException cnfex) { cnfex.printStackTrace(); }
}
}
>