Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (580)
games submitted by our members
Games in WIP (499)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Kryonet - Client continues to send but stops receiving  (Read 1398 times)
0 Members and 1 Guest are viewing this topic.
Offline lemm

Junior Newbie





« Posted 2013-05-05 07:59:47 »

Hello, I am trying to make a simple multiplayer game using Slick and Kryonet.

I am having problems with the client.  It will connect to the server and read a few messages, but after that, it stops receiving messages and it times out.  It doesn't stop sending messages to the server, however.  The server seems okay, as it is sending and receiving messages as I expect that it would. After 12s, the client times out.  The debugger also indicates that, after the first few packets received, the client listener received function is not being called at all.

I've tried running the client in debug mode and pausing it about a second after it connects.  The messages that ordinarily would not have been read now show up in the message queue.  Similarly, if I prematurely quit the client (not running in debug mode), the client log shows that the client has read the messages.

I'm confused!  Any help would be appreciated.

Code:
http://pastebin.java-gaming.org/349099d665d

Server Log: http://pastebin.com/TpPBv0dh
Client Log: http://pastebin.com/FZM9DB7q
Offline matheus23

JGO Wizard


Medals: 97
Projects: 3


You think about my Avatar right now!


« Reply #1 - Posted 2013-05-05 09:24:22 »

Hey, Nate, if you're (probably) reading this:
There seems to be some major issue with Kryonet.

Someone tried to run RuinsOfRevenge, which uses Kryonet for the networking. But he seems to have the exact same problem.

Hope you'll try to fix that, Nate!

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline Nate

JGO Kernel


Medals: 129
Projects: 3
Exp: 14 years


Esoteric Software


« Reply #2 - Posted 2013-05-05 10:54:43 »

@lemm, hard to say what the problem is. I guess you'll have to debug it. Set a breakpoint in Client where a message would be received and see what is going on. I see you have your own synchronization, maybe something goes wrong there.

@matheus23, I'm not aware of any issues, so I can't fix anything. If someone makes a minimal, executable example showing the problem then I can take a look.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline matheus23

JGO Wizard


Medals: 97
Projects: 3


You think about my Avatar right now!


« Reply #3 - Posted 2013-05-05 10:57:41 »

@matheus23, I'm not aware of any issues, so I can't fix anything. If someone makes a minimal, executable example showing the problem then I can take a look.

Yeah, I'm sorry. I can't reproduce it. But some people can. It seems to be dependent on the setup.

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline Nate

JGO Kernel


Medals: 129
Projects: 3
Exp: 14 years


Esoteric Software


« Reply #4 - Posted 2013-05-05 11:30:06 »

Yeah, unfortunately that sort of thing is really hard to fix. Sad

Offline matheus23

JGO Wizard


Medals: 97
Projects: 3


You think about my Avatar right now!


« Reply #5 - Posted 2013-05-05 11:39:47 »

Yeah, unfortunately that sort of thing is really hard to fix. Sad

As long as you have someone who appears to get that bug /** @see {user:lemm} */, it should be at least possible somehow.

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline lemm

Junior Newbie





« Reply #6 - Posted 2013-05-05 11:49:18 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
      
//Kryonet Client.java


// Line 221
if (select == 0) {
         // NIO freaks and returns immediately with 0 sometimes, so try to keep from hogging the CPU.
        long elapsedTime = System.currentTimeMillis() - startTime;
         try {
            if (elapsedTime < 25) Thread.sleep(25 - elapsedTime);
         } catch (InterruptedException ex) {
         }
      } else {
         Set<SelectionKey> keys = selector.selectedKeys();
         synchronized (keys) {
            for (Iterator<SelectionKey> iter = keys.iterator(); iter.hasNext();) {
               SelectionKey selectionKey = iter.next();
               iter.remove();

// ...



I started GameClient in a debugging session and I set the debugger to break if the selector had any keys (i.e., if the program reached "Set<SelectionKey> keys = selector.selectedKeys();").  The program would only break once every five seconds or so (or it wouldn't break at all before timing out).  In the client log, it was seen that all of the GameStateUpdate packets delivered from the server would then be processed at once.  So it looks like the client is receiving the messages from the server, but they can't be delivered to Kryonet for some reason, so they all clump up until they are all delivered at once.

I also removed the synchronized blocks in my code and it didn't seem to affect anything.

I am running the client and the server on the same computer.  The client is connecting to the server at 127.0.0.1.
Offline lemm

Junior Newbie





« Reply #7 - Posted 2013-05-05 12:11:43 »

Okay, it I have mitigated the problem by sending client position updates to the server at a slower rate.  I raised INPUT_SEND_RATE from 1000/60 to 1000/10 and my game is working as expected.
Offline HeroesGraveDev

JGO Kernel


Medals: 212
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


« Reply #8 - Posted 2013-05-05 12:24:30 »

Are you using
setTCPNoDelay(true);
?

It's been a while since I use Kryonet, but it may help.

Edit: If you were sending too fast, then that would do it.

Offline Nate

JGO Kernel


Medals: 129
Projects: 3
Exp: 14 years


Esoteric Software


« Reply #9 - Posted 2013-05-05 13:23:56 »

@lemm, if you run from SVN there has been a fix to Client and Server to avoid the sleep in the code you posted in most cases. Without this, in some cases this could lead to the 25ms sleep happening very often. Maybe this happened enough that your messages sent at 16ms intervals eventually fill the buffers.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline lemm

Junior Newbie





« Reply #10 - Posted 2013-05-05 21:40:16 »

Ah, that seems to have fixed it!  I bumped the Client send rate back to 60 messages per second and it's working as expected.

Thanks for your help.
Offline Nate

JGO Kernel


Medals: 129
Projects: 3
Exp: 14 years


Esoteric Software


« Reply #11 - Posted 2013-05-05 21:54:37 »

Sweet! Smiley Just committed a new fix for where one client is disconnected, other clients could get disconnected.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (43 views)
2014-04-15 18:08:23

BurntPizza (39 views)
2014-04-15 03:46:01

UprightPath (55 views)
2014-04-14 17:39:50

UprightPath (37 views)
2014-04-14 17:35:47

Porlus (53 views)
2014-04-14 15:48:38

tom_mai78101 (76 views)
2014-04-10 04:04:31

BurntPizza (135 views)
2014-04-08 23:06:04

tom_mai78101 (235 views)
2014-04-05 13:34:39

trollwarrior1 (196 views)
2014-04-04 12:06:45

CJLetsGame (204 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!