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)
I guess sockets was your best bet. You can try to research more info about JFS (Java Fast Sockets) which is a project from the University of A Coruña in Spain, but I'm not sure how far they went with it. More info here
There are so many ways for inter process communication between two machines - But I don't think any of them are going to be faster than raw sockets and will work for mouse events:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.