We are about to switch to a new forum software. Until then we have removed the registration on this forum.
So I'm trying to send coordinates between four players through a server using the networking library, and currently it seems like the easiest way to do that is to send a string such as:
positions= 0 + "," + ballX + "," + ballY + "," + p1 + "," + p2 + "\n";
myserver.write(positions);
And then receive it through:
void clientEvent(Client client) {
receivemessage=client.readUntil("\n");
datain = splittokens(receivemessage,",\n");
}
However, this seems to lag behind a bit as the buffer fills up and it slowly drifts further and further from real time. Should I stop sending strings and parsing them with splittokens() in favour of some other method, or should I just make sure that the client clears the buffer every once in a while?
Answers
The \n is not required in splittokens. Instead use
split(receivemessage, ',')
. This is because the reading of message will stop automatically as soon as a line break (=\n) is found.Thank you, I'll do that instead. So is splitToken() the way to go?
I'd say so. The other method may be to convert the float into the corresponding bytes and send to the server, then convert back to the corresponding float at the Server. But this is only recommended if the CPU is capable of the extra load but the network connection is too slow to send Strings.
For anyone who might stumble upon this post, the aforementioned lag was due to an inefficient use of
server.available()
. When I replaced it with an array of clients and usedserverEvent()
to assign positions in the array to connecting clients, the program ran much more smoothly.@Eiroth -- thanks so much for sharing your solution to this problem.
Could you share your post. The code available in the reference is very, very limited: https://processing.org/reference/libraries/net/serverEvent_.html
I have seen something along your comment in processing OSC lib: http://www.sojamo.de/libraries/oscP5/examples/oscP5broadcaster/oscP5broadcaster.pde
Kf
https://forum.Processing.org/two/discussion/16462/mpu6050-teapot-with-other-microcontrollers#Item_1
https://forum.Processing.org/two/discussion/17900/out-of-control-y-axis-rolling-graph#Item_1