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]
# 1
do you actually get a connection across the network or does it time out and you trap it and continue on?
morgalra at 2007-7-7 22:18:04 > top of Java-index,Other Topics,Java Game Development...
# 2
the connection are already establish between 2 computer over the network. shouldn't tcp/ip reliable? how come this problem occur? plz advise.
ckminga at 2007-7-7 22:18:04 > top of Java-index,Other Topics,Java Game Development...
# 3

Do a mySocketObject.getinetAddress() on the line before you send a message to the other computer and see what the address is of the computer you are connnected to -- it may be revealing, but if not, then let's see what code you have for connecting the sockets to the other computer. You may have a tcp/ip connection to the web, but everything I've used and seen so far has to have a connection between sockets when sockets are used.

morgalra at 2007-7-7 22:18:04 > top of Java-index,Other Topics,Java Game Development...
# 4

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(); }

}

}

>

ckminga at 2007-7-7 22:18:04 > top of Java-index,Other Topics,Java Game Development...
# 5
the code i post above are just portion of important part i took from my actual code.
ckminga at 2007-7-7 22:18:04 > top of Java-index,Other Topics,Java Game Development...
# 6
I don't see your listener for a new connection request--myServerSocket.accept();It seems to me the problem maybe there since you connect sometimes, but not always.
morgalra at 2007-7-7 22:18:04 > top of Java-index,Other Topics,Java Game Development...
# 7
What is the console error you get?
markuskidda at 2007-7-7 22:18:04 > top of Java-index,Other Topics,Java Game Development...
# 8

i do have ServerSocket.accept() which is written as ss.accept() in my coding(in the beginning of the code). after a few more testing, the program can run(send & receive data). but a while, the program have an error something to do with "numberFormat : 00-"

i can't really remember the actual word.

ckminga at 2007-7-7 22:18:04 > top of Java-index,Other Topics,Java Game Development...