Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Romans_I_XVI
Roku Guru

Why better performance with roInput than roDatagramSocket?

So I am working on a game that uses Android devices as the controls. The point of the game is to allow a large number of players to interact on one screen. I initially started out using roInput and RESTful HTTP to give the Roku instructions. Then I realized Roku can handle low level networking, it can receive raw UDP packets using roDatagramSocket. I am new to networking, but I thought I'd give it a shot because I knew it would be 10X faster than using RESTful HTTP communication. Not so!

It seems to be something to with roDatagramSocket creating a queue of its received messages, and if the Roku hangs, well then there is lots of latency. Also for my roInputEvent I am using port.GetMessage() where as in my roSocketEvent I am using wait(1, port) , because for whatever reason I never receive any data with port.GetMessage() on my roSocketEvent. roInput seems to drop the messages, if it hangs the sprites will just skip a few pixels, not hang and then process all the data moments later. It also takes a huge performance hit if there are multiple players connected, could it be that the Roku is receiving and then processing ALL the data from the players and thus becoming sluggish? How would I go about only processing whatever data is currently available on each loop through my while statement, instead of ALL data that has been captured since the last while loop?

These are just my best guesses so far as to what is going on.

I would really appreciate any help, I just spent my entire night switching to UDP for the performance, and it seems like a complete waste.
0 Kudos
3 REPLIES 3
Romans_I_XVI
Roku Guru

Re: Why better performance with roInput than roDatagramSocke

I think I just realized what's wrong and I feel like an idiot. Is amazing what a night of sleep can do for your thinking process.

I am currently only processing 1 packet of data each pass through my entire while statement. So if I'm running at 60fps I'm only processing 60 packets per second. But as more connections are active I may be receiving 100+ packets per second. And thus the state of my game is far behind.

Think I just need to process all available packets each pass through...

Not at home to try this, but logically it makes sense.
0 Kudos
Komag
Roku Guru

Re: Why better performance with roInput than roDatagramSocke

I hope you're right - I always like to give my mind a task and do other things for a while, then the answer, or at least a new idea, comes 8-)
0 Kudos
Romans_I_XVI
Roku Guru

Re: Why better performance with roInput than roDatagramSocke

Seems to have worked 😄 . Can't fully test right now, but i know it is now reading multiple packets on each loop through . 8-)
0 Kudos