I made a java program just for fun this program allows you to control the seconds computer mouse using the first computer's mouse. so everytime the mouse moves some the x and the y of the cursor is sent client application. which then uses the robot class to move the mouse. right now I am using sockets to communicate and it is really slow what is a better way to do it any help would be apritited. if possible please provide some code thanks
If both applications live in different virtual machines, then communication via sockets is a very good approach.
If it is too slow, you may consider
Considering you comment to this answer:
As you send bytes over sockets, performance will be increased if you encode the mouse positions to byte
values rather then to String
:
int x = getX();
int y = getY();
// let's assume we have a 16Bit / 2Byte range for both values (practica)
byte[] message = new byte[4];
message[0] = (byte) (x >> 8) & 0xff;
message[1] = (byte) x & 0xff;
message[2] = (byte) (y >> 8) & 0xff;
message[3] = (byte) y & 0xff;
sendViaSocket(message);
(It starts and ends with some magic, the point is the encoding)