Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (489)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (555)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Networking & Multiplayer / [KryoNet] Client can't send and receive at the same time ? on: 2013-05-06 19:14:36
Hi,

I'm trying to code a simple client/server using KryoNet but I'm struggling with something, my client can't receive packets while sending.

When I hold the right key I want my player to move 1pixel to the right. In my situation when I hold the right key my player moves 1 pixel to the right, then stop moving, and finally when I release the key he literally teleports himself in the right direction. I other words the client receive almost all the packets at one time.

Here's my code:

Client:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
public void launch() throws SlickException, IOException {
      AppGameContainer container = new AppGameContainer(this);
      container.setMinimumLogicUpdateInterval(10);
      container.setMaximumLogicUpdateInterval(10);
      container.setUpdateOnlyWhenVisible(false);
      container.setAlwaysRender(true);


      client = new Client();
      ClassRegister.register(client.getKryo());
      client.addListener(new CustomListener(this));

      client.start();

      if (!connected) {
         Log.set(Log.LEVEL_TRACE);
         try {
            client.connect(5000, host, port);
            connected = true;
         } catch (IOException e) {
            e.printStackTrace();
         }
      }
      container.start();
   }


CustomListener:
1  
2  
3  
4  
5  
6  
7  
8  
@Override
   public void received (Connection connection, Object object) {
     
      if (object instanceof MoveResponse) {
         MoveResponse response = (MoveResponse) object;
         getPlayer().move(response.dir);
      }
   }


Server:
1  
2  
3  
4  
5  
6  
7  
8  
private void start() throws IOException {
      server = new Server();
      ClassRegister.register(server.getKryo());
      server.bind(port);
      server.addListener(new ServerListener(this));
      server.start();
      Log.set(Log.LEVEL_TRACE);
   }


ServerListener:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
@Override
   public void received(Connection connection, Object object) {
                if (object instanceof MoveRequest) {
         MoveRequest request = (MoveRequest) object;
         
         MoveResponse response = new MoveResponse();
         response.dir = request.dir;
         connection.sendTCP(response);
      }
   }


Input:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
public void update() {
      movePlayer();
   }

private void movePlayer() {
      if (pressedRight) {
         sendMoveRequest(3);
      } else if (pressedUp) {
         sendMoveRequest(1);
      } else if (pressedDown) {
         sendMoveRequest(2);
      } else if (pressedLeft) {
         sendMoveRequest(4);
      }
   }

   public void keyPressed(int key, char c) {
      if(key == goDown) {
         pressedDown = true;
      } else if(key == goLeft) {
         pressedLeft = true;
      } else if(key == goUp) {
         pressedUp = true;
      } else if(key == goRight) {
         pressedRight = true;
      }
   }

   public void keyReleased(int key, char c) {
      if(key == goDown) {
         pressedDown = false;
      } else if(key == goLeft) {
         pressedLeft = false;
      } else if(key == goUp) {
         pressedUp = false;
      } else if(key == goRight) {
         pressedRight = false;
      }
   }



I seriously don't see where I'm messing up  Sad Any help?
2  Game Development / Networking & Multiplayer / Re: [Kryonet] Client disconnects after packet sent? on: 2013-03-06 11:55:33
Weird question but are you using the same version of Kryonet on both sides? Can you post some code?
3  Game Development / Networking & Multiplayer / Re: [Kryonet] Client disconnects after packet sent? on: 2013-03-06 10:29:21
Did you registered the classes in the same order on client/server side ?

Any stacktrace ?
4  Games Center / Archived Projects / Re: Smorspelet on: 2010-09-28 07:19:27
Very addictive little game =p.
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (14 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (29 views)
2014-08-22 19:31:30

atombrot (41 views)
2014-08-19 09:29:53

Tekkerue (38 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (24 views)
2014-08-16 06:20:21

Tekkerue (34 views)
2014-08-16 06:12:11

Rayexar (72 views)
2014-08-11 02:49:23

BurntPizza (48 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!