I managed to set up a server(on PC) and a Client (on device) thru the IP address .Now I want to send a meesage to the PC to move left or right depending if I hit the volume up or down…
Client:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP)
{
mtcpclient.write(1); //I need to implement write function..
return true;
}
else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN){
mtcpclient.write(2);//I need to implement write function..
return true;
}
return super.onKeyDown(keyCode, event);
}
Server:
private void processCommand(int command) {//Recieve int and decide to go right or left
try {
Robot robot = new Robot();
switch (command) {
case 1:
robot.keyPress(KeyEvent.VK_RIGHT);
System.out.println("Right");
break;
case 2:
robot.keyPress(KeyEvent.VK_LEFT);
System.out.println("Left");
break;
}
} catch (Exception e) {
e.printStackTrace();
}
If your question is how to send data…here is a simple example on how to send data via TCP.
Then you just need to write a similar listener on your computer.