⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jremserverprotocol.java

📁 JRemoteControl is a simple Java&#8482 driven bluetooth remote control.It allows you to initiate virt
💻 JAVA
字号:
/* * JRemCntl - Copyright (C) 2007 Filippo Di Vattimo <fildiv@gmail.com> * See COPYING */package fildiv.jremcntl.server.core;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.util.Vector;import fildiv.jremcntl.common.core.Command;import fildiv.jremcntl.common.core.CommandResult;import fildiv.jremcntl.common.core.Config;import fildiv.jremcntl.common.core.Context;import fildiv.jremcntl.common.proto.ByteReader;import fildiv.jremcntl.common.proto.ByteWriter;import fildiv.jremcntl.common.proto.JRemAbstractProtocol;import fildiv.jremcntl.common.proto.JRemDataTransferException;import fildiv.jremcntl.common.proto.JRemProtocolMessagesType;public class JRemServerProtocol extends JRemAbstractProtocol {	public JRemServerProtocol(InputStream in, OutputStream out) {		super(in, out);	}	public synchronized void sendCmdResponse(CommandResult result) throws JRemDataTransferException {				ByteWriter bw = new ByteWriter();				bw.setBytes(null);		result.write(bw);		int size = bw.getSize();		createMessage(bw, size, 				JRemProtocolMessagesType.MSG_TYPE_SEND_COMMAND_RESULT);		result.write(bw);				sendMessage(bw.getBytes());	}		public void sendConfig(Config config) throws JRemDataTransferException {				ByteWriter bw = new ByteWriter();				bw.setBytes(null);		addConfig(bw, config);				int size = bw.getSize();		createMessage(bw, size, 				JRemProtocolMessagesType.MSG_TYPE_SEND_CONFIG);		addConfig(bw, config);				sendMessage(bw.getBytes());				}		public int retrieveCommandID() throws JRemDataTransferException {				try {						ByteReader br = readPacket(true);			int command = br.getInt();			if (command != JRemProtocolMessagesType.MSG_TYPE_SEND_COMMAND_ID)				throw new JRemDataTransferException(						"Invalid command, expected PROTO_CMD_COMMAND");						return br.getInt();					} catch (IOException e) {			throw new JRemDataTransferException(e);		}	}		public void closeClientConnection() {		ByteWriter bw = new ByteWriter();		createMessage(bw, 0, 				JRemProtocolMessagesType.MSG_TYPE_CLOSE_CONNECTION);				try {			sendMessage(bw.getBytes());		} catch (JRemDataTransferException e) {		}	}	public void close() {		closeClientConnection();		super.close();	}	/*	 * Implementation	 */		protected void addConfig(ByteWriter bw, Config config) {				bw.addString(config.getName());		Vector contexts = config.getContexts();		addContexts(bw, contexts);	}		protected void addContexts(ByteWriter bw, Vector contexts) {				bw.addInt(contexts.size());				for (int index = 0; index < contexts.size(); ++index) {			Context context = (Context) 				contexts.elementAt(index);						sendContext(bw, context);					}	}		private void sendContext(ByteWriter bw, Context context) {		bw.addInt(context.getID());		bw.addString(context.getDesc());		bw.addShort(context.getDefView());		bw.addInt(context.getCommands().size());				Vector commands = context.getCommands();				for (int index = 0; index < context.getCommands().size(); ++index) {						Command command = (Command) commands.elementAt(index);						sendCommand(bw, command);		}	}		protected void sendCommand(ByteWriter bw, Command command) {		bw.addInt(command.getID());		bw.addString(command.getDesc());		bw.addString(command.getKey());		bw.addString(command.getQuestion());	}	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -