20. Flash (クライアント) 側 から Java( サーバ ) への送信 public static const TALK:int = 0x0000; public function writeData(bytes:ByteArray):void var bytes:ByteArray = new ByteArray() bytes.writeByte(TALK); bytes.writeUTF(message); bytes.writeUnsignedInt(color); }
21. Java( サーバ ) で受信 public static final short TALK = 0x0000; public class TalkData implements CommandData{ public void readData(ByteBuilder in) { byte commandId = in.getByte(); String message = in.getUTF(); int color = in.getInt(); talk(user, message, color); } }
22. 同一エリア内のユーザに配信 public void talk(ChatUser user, String message, int color) throws ServiceException { // 今いるエリアを取得 ChatArea chatArea = user.getChatArea(); // 話した内容を Data(Command) 化 TalkResultData talkResult = new TalkResultData(user.getAmebaId(), user.getNickname(), message, color); // broadcast for (ChatUser user : chatArea.getUsers()) { CommandConnection conn = user.getConnection(); conn.sendCommand(talkResult); } }
23. public static final short TALK_RESULT = 0x0001; public class TalkResultData implements CommandData{ public TalkResultData(String amebaId, String nickname, String message, int color) { this.commandId = CommandId.TALK_RESULT; this.amebaId = Binaries.toBytes(amebaId); this.nickname = Binaries.toBytes(nickname); this.messageByte = Binaries.toBytes(message); this.color = color; } // Java( サーバ ) 側 から Flash (クライアント) への送信 public void writeData(ByteBuilder out) { out.put Byte (commandId); out.putShort((short)messageByte.length); out.put(messageByte); out.putInt(color); out.putShort((short)amebaId.length); out.put(amebaId); out.putShort((short)nickname.length); out.put(nickname); } }
24. Flash (クライアント) の 受信 public static const TALK_RESULT:int = 0x0001; public function readData(bytes:ByteArray):void { commandId = bytes.readUnsignedByte(); message = bytes.readUTF(); color = bytes.readUnsignedInt(); amebaId = bytes.readUTF(); nickname = bytes.readUTF(); } public function talk(msg:String, color:uint):void _chat.addBubble(new ChatBubble(msg, color)); }
25. Flash (クライアント) の 受信 public static const TALK_RESULT:int = 0x0001; public function readData(bytes:ByteArray):void { commandId = bytes.readUnsignedByte(); message = bytes.readUTF(); color = bytes.readUnsignedInt(); amebaId = bytes.readUTF(); nickname = bytes.readUTF(); } public function talk(msg:String, color:uint):void _chat.addBubble(new ChatBubble(msg, color)); }