Http connection is delaying canvas.keypressed

Hello all!

I havn't been back here for quite some time, but I have one problem that is stumping me for the moment. My name is Adam Schmelzle, and I have been making J2ME games for a while(Attack Chopper 1/2, Attack Breaker Pro, Attack Brain), so I'm not really new to this.

I am working on an online system for my next game, and all my messaging is done through an HttpConnection for now. I am trying to make this compatible with Midp1.0, which is why I am using http. I have everything working fine on the Sun WTK25, but when it comes to using my phones, I run into problems with my canvas.keypressd() events.

Sometimes the keypresses/releases will work fine, sometimes a delay of a second or two, sometimes it won't fire until I hit some buttons a few times.

Example 1: So I can press and hold "up", get the "up-pressed" event, wait a couple seconds then release, but not get the "up-release" event. If I press "up" again I don't get the "up-pressed" event at all, but when I release I finally get the original "up-release" from the first keypress.

Example 2: Press "up", get "up-pressed" event. Release "up", and never get the "released-up" event at all.

This only happens if my network IO thread is sending/receiving data. On one of my phones I experience problems for the entire duration of my game after even doing just 1 httpConnection on the main game thread.

I guess I want to know if anybody has some advice for me regarding network IO. I assume that somewhere along the line the runtime is starving the thread that handles the keypresses, but is there any way to avoid this? Maybe sleeping/waiting briefly(1ms) in the middle of transfering data every once in a while? It does take a second or two to send/recieve.

I plan on implementing socket IO for Midp2.0 phones after I've got all the kinks worked out for Midp1.0. My server will use nio, which I have used before in an applet game with positive results.

Help please,

Adam.

[2010 byte] By [hooblea] at [2007-11-27 4:48:32]
# 1

hm thats pretty strange. I'd hate to ask the stupid question, but you are managing an explicit secondary thread for your network IO right?

if so: **** thats weird. i wonder of the oem implementations discard a keyup if n number of ms have passed? and the thread swapping is delaying the cpu from getting back to your UI thread?

if not: you should have that :-P

pandora_fooa at 2007-7-12 10:01:27 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2

Yeah, I have a separate thread that is dedicated to network I/O. The main game thread runs fine while the network updater thread is executing.

The part that bugs me is that I can have multiple threads all doing different computationally expensive things and there are no problems; but as soon as I am using the httpconnection the keypresses becomre irregular.

I know this isn't a problem with my code, so I was hoping other people that have experienced this problem could point me at a workaround. There are soo many quirky things when doing mobile games, that nothing surprises my anymore. Are there actually ANY phones out there that follow the Midp1.0 or 2.0 spec properly?

*update* I purchased a new phone to test with, and it doesn't show any of the problems with the keypressed() events. I guess I'll just have to ignore it for now, since there's not likely anything I can do about it.

Message was edited by:

hooble

hooblea at 2007-7-12 10:01:27 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3

Another finding: The keypressed problems went away when I 'hacked' my phone to remove all the network 'allow/deny' screens. It looks like when the phone popped up the screen asking if I would allow the network connection happened, it didn't clean itself up after responding. This really bugs me. There was absolutely nothing I could do about this problem.

hooblea at 2007-7-12 10:01:27 > top of Java-index,Java Mobility Forums,Java ME Technologies...