HoverCatz
HoverCatz

Reputation: 75

Sending ints, receives wrong data

I'm trying to send the player's position (x, y) to the client from the Server. Everything else seems to work, but not these 2 ints. I can send other integers, for example 3456, and it will receive 3456. But these wont work.

Server Java code:



    public void sendAccountInformation() throws IOException {
            dos.write(player.id);
                main.log(player.id);
            dos.println(player.username);
                main.log(player.username);
            dos.write(player.x);
                main.log(player.x);
            dos.write(player.y);
                main.log(player.y);
            dos.write(player.mapid);
                main.log(player.mapid);

            dos.flush();
        }

Server output:

0
sdfsdffsd
544
384
0

The above is the correct information that should be sent.

Client Java code:



    public void loadAccount() throws IOException {
            int id = dis.read();
            main.player = new Player(id, main);
                main.log(id);

            main.player.username = dis.readLine();
                main.log(main.player.username);

            main.player.x = dis.read();
                main.log(main.player.x);
            main.player.y = dis.read();
                main.log(main.player.y);
            main.player.mapid = dis.read();
                main.log(main.player.mapid);
        }

Client output:

0
sdfsdffsd
63
63
0

As you can see, the two integers (544 and 384) was changed into (63 and 63). But EVERYTHING else sends and is received correctly?

Upvotes: 2

Views: 118

Answers (1)

AllTooSir
AllTooSir

Reputation: 49362

I believe you should try using writeInt() and readInt() to write and read int.

Upvotes: 2

Related Questions