2013-07-10 3 views
2

플레이어의 위치 (x, y)를 서버에서 클라이언트로 보내려고합니다. 다른 모든 것은 작동하는 것처럼 보이지만이 2 개의 int는 작동하지 않습니다. 예를 들어 3456과 같은 다른 정수를 보낼 수 있으며 3456을받습니다. 그러나 이것들은 작동하지 않습니다.ints를 보내면 잘못된 데이터가 수신됩니다.

서버 자바 코드 :

 


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

서버 출력 :

 
0 
sdfsdffsd 
544 
384 
0 

은 상기 전송되어야 정확한 정보이다.

클라이언트 자바 코드 :

 


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

클라이언트 출력은 : 당신이 볼 수 있듯이

 
0 
sdfsdffsd 
63 
63 
0 

, 두 개의 정수 (544 및 384) (63, 63)로 변경되었습니다. 그러나 그 밖의 모든 사람들은 보내고 제대로 받습니까?

+4

여기에 관련 코드를이 사이트에 게시하십시오. –

+0

음? 스크린 샷의 URL이 포함 된 pastebin에 링크하는 대신 코드 서식 블록에 코드를 붙여 넣을 수 있습니까? – hexafraction

+0

이 문제를 재현하는 코드를 매우 짧게 표시 할 수 있습니까? 예 : 필요하지 않은 GUI 코드없이. –

답변

2

나는 을 쓰고 읽으려면 writeInt()readInt()을 사용해야한다고 생각합니다.

+0

나는 그것을 시험해보고 결과를 게시 할 것이다. 감사! –

+0

완벽하게 작동합니다. 도움을 주신 모든 분들께 감사드립니다. :) 누군가이 질문을 "SOLVED"로 설정하는 방법을 말해줍니다. –

+0

수락 할 답변의 등급 아래에있는 "확인"표시를 클릭하십시오. – Jokab

관련 문제