我想在java上以VNC的形式编写一个应用程序。
起初我尝试流式传输我的鼠标位置,但我刚在学校学习了一些Java。
我的代码:
private Maus mouse;
static int cX;
static int cY;
public TestMaus() {
mouse = new Maus();
}
public void main() throws Exception {
String sentence;
String modifiedSentence;
BufferedReader inFromUser = new BufferedReader( new InputStreamReader(System.in));
Socket clientSocket = new Socket("", 6789);
while(true)
{
DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
sentence = String.valueOf(mouse.posX + "I" + mouse.posY);
outToServer.writeBytes(sentence + '\n');
modifiedSentence = inFromServer.readLine();
System.out.println("FROM SERVER: " + modifiedSentence);
clientSocket.close();
}
}
public int posX, posY;
public Maus(){
addMouseMotionListener(new MouseMotionAdapter() {
public void mouseMoved(final MouseEvent e) {
posX = e.getX();
posY = e.getY();
}
});
}