作为Java开发人员,你每天通过Synergy使Linux台式机和笔记本协作时,可能会面临一个困扰: 每天启动台式机上的synergy
c时,你都要去动下台式机的鼠标和键盘,在台式机中输入笔记本的IP,最后再启动syngergyc
c.
下面这个工具就是可以让你在笔记本上启动台式机的syngergyc
c,并连接笔记本上的synergy server; 这样一来,你就可以彻底不碰台式机了。
使用前提:
1. 你的Linux台式机中已安装Syngergc,且syngergc命令在path中。
2. 你的Linux台式机基本不关机
工具安装办法:
1. 在linux台式机中部署下面的java servlet应用
package kent.web.synergyutil; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class SynergycServlet extends HttpServlet { private static final long serialVersionUID = -2286225907488120316L; @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { PrintWriter out = resp.getWriter(); String serverIp = getServerIp(req); out.println("<h1>Synergyc Controller</h1>"); if (serverIp == null || serverIp.isEmpty()) { StringBuffer sb = new StringBuffer(); sb.append("<b>Please input your synergy server's IP here: </b>\n"); sb.append("<form action='' method='get'> \n"); sb.append(" <input name='serverIp' value='" + getDefaultIp(req) + "'/> \n"); sb.append(" <input name='GO' type='submit'/> \n"); sb.append("</form> \n"); out.println(sb); return; } out.println("<div>" + exec("killall synergyc") + "</div>"); out.println("<div>" + exec("synergyc " + serverIp) + "</div>"); } private String getDefaultIp(HttpServletRequest req) { return req.getRemoteAddr(); } private String exec(String cmd) throws IOException { try { Process p = Runtime.getRuntime().exec(cmd); int exitValue = p.waitFor(); String response = "Executing: " + cmd + ". Exit value is " + exitValue; return response; } catch (InterruptedException e) { throw new IllegalStateException(e); } } private String getServerIp(HttpServletRequest req) { String serverIp = req.getParameter("serverIp"); if (serverIp != null) { serverIp = serverIp.trim(); } return serverIp; } }
<!--web.xml--> <web-app> <servlet> <servlet-name>synergycServlet</servlet-name> <servlet-class>kent.web.synergyutil.SynergycServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>synergycServlet</servlet-name> <url-pattern>/sc</url-pattern> </servlet-mapping> </web-app>
2. 启动Servlet应用
3. 在笔记本的浏览器中输入:
http://台式机:8080/sc,将看到:
输入框里已有的IP就是你的服务端IP,一般不用改。提交后,