Hey folks! I have a disability that limits my mobility, and I primarily use my index finger for everything. Right now, I use an emulated Xbox controller on my phone to control games via an app called PC Remote by Monect. I'm attempting to make my own version of this app since I want to customize it and add features that suit my needs. I've made some progress with coding, despite not having much experience, thanks to AI helping me along the way.
The app has functionalities like Xbox controller buttons and a joystick, but there's still lag when I'm trying to control my PC. I've switched from TCP to UDP for better speed, and while it's an improvement, I'm still not getting the instant response I want. I'm looking for advice on how to optimize my code to reduce this lag even further. If you're willing to take a look at my code, I'll deeply appreciate any guidance or suggestions on what to tweak. I really want to get back to playing games that require multiple inputs! Here's the link to my GitHub if you're interested: https://github.com/Colonelwheel/Simplecontroller. Would love to hear any thoughts or tips you have!
1 Answer
It sounds like you're facing a buffering issue. I noticed you're sending and receiving data in chunks of 1024 bytes, which might be causing some stalling. Consider looking into unbuffered socket I/O; it'll help you with the lag you're experiencing. Also, switching back to TCP might be worth it, since it automatically handles data loss, unlike UDP. You could get some dropped inputs with UDP unless you put in extra work to manage it, which might not be worth the trouble for your application.
Thanks for the tips! I actually made some adjustments after your advice. I’ve disabled Nagle's algorithm to reduce latency, but I'm still seeing some jittery behavior with inputs. It feels like the controls freeze and then suddenly catch up. Are there any development tools you recommend to help me trace what’s going on?