Hey everyone, when my server sends 2d int array to client it stops receiving any more packets.
static int[][] getMapToSend(Location){
int[][] a = new int[40][40];
int x1 = 0,y1 = 0;
for(int i = l.x-20;i<l.x+20;i++){
for(int j = l.y-20;j<l.y+20;j++){
if(!ServerState.chunkLoaded(l.x, l.y)){
a[x1][y1] = ServerState.loadChunk(i, j).tiles[i%100][j%100];
}else{
a[x1][y1] = ServerState.getChunk(i,j).tiles[i%100][j%100];
}
x1+=1;
}
y1+=1;
x1=0;
}
return a;
}
static void sendMap(Player p,Location l,Connection c){
int[][] mapToSend = getMapToSend(l);
server.sendToTCP(c.getID(), mapToSend);
}
Here are the loadChunk and getChunk methods
static Chunk[][] map = new Chunk[200][200];
public static Chunk loadChunk(int x,int y){
int[][] a = new int[100][100];
BufferedReader br = null;
File f = new File("gamestate/map_"+x/100+"_"+y/100+".txt");
if(!f.exists()){
try {
f.createNewFile();
} catch (IOException ex) {
Logger.getLogger(ServerState.class.getName()).log(Level.SEVERE, null, ex);
}
writeArrayToFile(map_template, "gamestate/map_"+x/100+"_"+y/100+".txt");
}
try {
br = new BufferedReader(new FileReader("gamestate/map_"+x/100+"_"+y/100+".txt"));
} catch (FileNotFoundException ex) {}
try {
for (int i = 0; i <100; i++) {
String[] st = br.readLine().trim().split(" ");
for (int j = 0;j < 100; j++) {
a[i][j] = Integer.parseInt(st[i]);
}
}
} catch (IOException ex) {}
Chunk c = new Chunk();
c.tiles=a;
c.x=x/100;
c.y=y/100;
return c;
}
public static Chunk getChunk(int x,int y){
return map[x/100][y/100];
}
Also Chunk class is basically a 2d 100x100 int array with coordinates.
If I would send an emty array instead I would get java.nio.BufferOverflowException on server side and ofc client still disconnects.
Please say if I forgot to add some information. Kryonet seems to be configured normally and everything else works.