To be honest, i didnt really want to show this thus its not a game at all, but the problem is related anyway to realtime networking so and maybe in future ill make a game knowing such things,
This is a test and not the thing i want that app to work (actually i want to view something from different projection and edit it along on other screen)
I noticed one thing - it lags a server too (phone on the right)
Then i realized i use blocking sockets, this is the main issue why its lagging so much, write and read functions (actually select for client socket) hold up a thread which holds up main thread from processing packets, and uploading to a thread commands it wants to send,
Basically even if i release a finger sometimes i need to wait even 10 seconds for client to actually receive all commands and thus it will insert a box on its app, but thats odd i have sent all commands from server to client and client processes like 512 bytes of data in 10 seconds..... When select and read should return immideatly after knowing theres a data to read, anyway i read 256 per thread loop,
Maybe it has something to do with multithreaded layer i wrote that it works like that:
There is a class named desktop window manager ?
It contains client and server class and a list of windows along other virtual functions
But the main process of a frame that is run on thread looks like this
Thread2
Check whenever theres a data to be read
CmdsIn.Lock();
Add data to CmdsIn only if they are valid commands
CmdIn.Unlock();
Read data
CmdsOut.Lock();
Send to server all commands pending to be sent
CmdsOut.Unlock();
Now in main thread i am actually processing data
It contains a magic loop ? thus i think it aint that safe
while (client->commands_received.Locked()) {}//block till nothing uses it
socket->CmdIn.Lock();
Then i read from CmdsIn
CmdIn.Unlock();
And so on in a thread2 i have the same
While (CmdIn.Locked) {}
Before adding commands to cmdin
And while (cmdOut.Locked) {}
Before sending any pending commands
So main thread doesnt use this block of memory at the same time, thus i didnt check which of these two (read select or write) or while() loops are causing lag
And with tcp nodealy well it may look like its a bit faster but it aint realtime,
Even when i press a button this packet sometimes need to be received in processed in 1 to 2 seconds after other phone sends it, so somethings wrong and there are so much things to check,
However i dont know how to manage nonblocking sockets,
So i asked about udp cause blushogun said that they are for realtime networking
And acfually if i send a command which is 20 bytes long and it takes a second to process on other peer so thats definetky something way wrong with tcp protocol, (along with my implementatikn) not to mention multiplayer games that handle way more data at realtime
I really wanted to avoid this cause topic might be removed but well.......