首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

心血来潮后的一个话音软件

2012-07-08 
心血来潮后的一个语音软件直接上视频?http://v.youku.com/v_show/id_XNDA4ODU5NzMy.html??Android源码?服

心血来潮后的一个语音软件

直接上视频

?

http://v.youku.com/v_show/id_XNDA4ODU5NzMy.html

?

?

Android源码

?

服务器端

import java.io.IOException;import java.net.DatagramPacket;import java.net.DatagramSocket;import java.util.HashMap;import java.util.Map;public class RunCmd {private static final int BUFMAX = 255; // Maximum size of echo datagramprivate static Map<String , Runnable> cmdThreadPool;public static void main(String[] args) {RunCmd rc = new RunCmd();rc.serverRun();}public RunCmd() {cmdThreadPool = new HashMap<String , Runnable>();cmdThreadPool.put("open_firefox", new cmdRunnable("C:\\Program Files\\Mozilla Firefox\\firefox.exe"));cmdThreadPool.put("open_baidu", new cmdRunnable("C:\\Program Files\\Mozilla Firefox\\firefox.exe http://www.baidu.com"));cmdThreadPool.put("close_firefox", new cmdRunnable("taskkill /im firefox.exe"));cmdThreadPool.put("open_notepad", new cmdRunnable("notepad"));cmdThreadPool.put("close_notepad", new cmdRunnable("taskkill /im notepad.exe"));cmdThreadPool.put("open_qq", new cmdRunnable("C:\\Program Files\\Tencent\\QQ\\Bin\\QQProtect\\Bin\\QQProtect.exe"));cmdThreadPool.put("open_wps", new cmdRunnable("C:\\Program Files\\Kingsoft\\WPS Office Personal\\office6\\wps.exe /w"));cmdThreadPool.put("close_wps", new cmdRunnable("taskkill /im wps.exe"));cmdThreadPool.put("open_e", new cmdRunnable("explorer e:"));cmdThreadPool.put("close_computer", new cmdRunnable("shutdown /s /t 0"));}public void serverRun(){try {DatagramSocket socket = new DatagramSocket(3693);DatagramPacket packet = new DatagramPacket(new byte[BUFMAX], BUFMAX);    while (true) { // Run forever, receiving and echoing datagrams    socket.receive(packet); // Receive packet from client        String cmd = new String(packet.getData(),packet.getOffset() , packet.getLength());        System.out.println(cmd);        byte[] replayMsg;    if(handlerCmd(cmd)){    replayMsg = new String("OK").getBytes();        }else{    replayMsg = new String("NO").getBytes();        }    DatagramPacket replayPacket = new DatagramPacket(replayMsg,replayMsg.length,    packet.getAddress() , packet.getPort());        socket.send(replayPacket); // Send the same packet back to client            packet.setLength(BUFMAX); // Reset length to avoid shrinking buffer    }} catch (IOException e) {System.out.println(e.getMessage());e.printStackTrace();}        }public boolean handlerCmd(String cmd){Runnable cmdRun = cmdThreadPool.get(cmd.trim());if(cmdRun != null){new Thread(cmdRun).start();return true;}else{return false;}}public class cmdRunnable implements Runnable{private String cmd;public cmdRunnable(String cmd){this.cmd = cmd;}public void run(){try {Runtime run = Runtime.getRuntime();run.exec(cmd);} catch (IOException e) {e.printStackTrace();}}}/*public class OpenFireFox implements Runnable{public void run(){String open_cmd = "C:\\Program Files\\Mozilla Firefox\\firefox.exe";try {Runtime run = Runtime.getRuntime();run.exec(open_cmd);} catch (IOException e) {e.printStackTrace();}}}public class OpenBaiDu implements Runnable{public void run(){String open_cmd = "C:\\Program Files\\Mozilla Firefox\\firefox.exe http://www.baidu.com";try {Runtime run = Runtime.getRuntime();run.exec(open_cmd);} catch (IOException e) {e.printStackTrace();}}}public class CloseFireFox implements Runnable{public void run(){String close_cmd= "taskkill /im firefox.exe";try {Runtime run = Runtime.getRuntime();run.exec(close_cmd);} catch (IOException e) {e.printStackTrace();}}}public class OpenNotepad implements Runnable{public void run(){String open_cmd = "notepad";try {Runtime run = Runtime.getRuntime();run.exec(open_cmd);} catch (IOException e) {e.printStackTrace();}}}public class CloseNotepad implements Runnable{public void run(){String close_cmd= "taskkill /im notepad.exe";try {Runtime run = Runtime.getRuntime();run.exec(close_cmd);} catch (IOException e) {e.printStackTrace();}}}public class OpenQQ implements Runnable{public void run(){String open_cmd = "C:\\Program Files\\Tencent\\QQ\\Bin\\QQProtect\\Bin\\QQProtect.exe";try {Runtime run = Runtime.getRuntime();run.exec(open_cmd);} catch (IOException e) {e.printStackTrace();}}}public class OpenWPS implements Runnable{public void run(){String open_cmd = "C:\\Program Files\\Kingsoft\\WPS Office Personal\\office6\\wps.exe /w";try {Runtime run = Runtime.getRuntime();run.exec(open_cmd);} catch (IOException e) {e.printStackTrace();}}}public class CloseWPS implements Runnable{public void run(){String close_cmd= "taskkill /im wps.exe";try {Runtime run = Runtime.getRuntime();run.exec(close_cmd);} catch (IOException e) {e.printStackTrace();}}}public class OpenE implements Runnable{public void run(){String open_cmd = "explorer e:";try {Runtime run = Runtime.getRuntime();run.exec(open_cmd);} catch (IOException e) {e.printStackTrace();}}}public class CloseComputer implements Runnable{public void run(){String open_cmd = "shutdown /s /t 0";try {Runtime run = Runtime.getRuntime();run.exec(open_cmd);} catch (IOException e) {e.printStackTrace();}}}*/}
?

?

热点排行