📄 httpmonitorserver.java
字号:
/*
* @(#)HttpMonitorServer.java 1.00 2005-9-7
*
* Copyright 2005 BeanSoft Studio. All rights reserved.
* PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
package studio.beansoft.remotecontrol.server;
import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import studio.beansoft.util.logging.Logger;
import com.keypoint.PngEncoder;
import com.keypoint.PngEncoderB;
/**
* HttpMonitorServer provides a http monitor server that according to the client
* requirements.
* This server parse parameters send by the client using HTTP GET
* method, and then response client with a image of the server screen, finally
* execute keyboard and mouse operations on the server.
*
* Chinese documents:
* 提供一个 HTTP 符合客户端要求的监视服务器. 这个服务器分析客户端通过 HTTP GET 方法传递过来
* 的参数, 返回客户端服务器屏幕的图像, 最后在服务器上执行键盘和鼠标操作.
*
* @author BeanSoft
* @version 1.00 2005-9-7
*/
public class HttpMonitorServer extends TcpMonitorServer {
/**
* Service client as a HTTP monitor server.
* @see studio.beansoft.remotecontrol.client.HttpCommunicationThread
*/
public void serviceRequest() throws IOException {
try {
long startTime = System.currentTimeMillis();
BufferedReader in = new BufferedReader(new InputStreamReader(
super.clientInput));
String uri = in.readLine();
String resource = uri.substring(uri.indexOf('/')+1, uri.lastIndexOf('/')-5);
doEventHandle(resource);
// Logger.getLogger("HttpMonitorServer").debug("Request: " + resource);
clientOutput.println("HTTP/1.0 200 OK");// Send a http ok response
// ImageIO.write(captureScreen(), "png", clientOutput);
clientOutput.println("Content_Type:image/png");
clientOutput.println();// End HTTP response header
// Buffered output
BufferedOutputStream bout = new BufferedOutputStream(clientOutput, 10240);
BufferedImage bi = captureScreen();
// JPEG format, faster, but big file
// JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bout);
// JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
// param.setQuality(1.0f, false);
// encoder.setJPEGEncodeParam(param);
//
// encoder.encode(bi);
// Keypoint png file output
PngEncoderB pngb = new PngEncoderB(bi,
PngEncoder.NO_ALPHA, 0, 9);
bout.write(pngb.pngEncode());
bout.flush();
Logger.getLogger("HttpMonitorServer").debug("Process time:" + (System.currentTimeMillis() - startTime));
} catch (Exception e) {
Logger.getLogger("HttpMonitorServer").fatal("HTTP Server failer:" + e.getLocalizedMessage());
}
}
/**
* Start the http server.
* @param args
*/
public static void main(String[] args) {
new HttpMonitorServer();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -