/// <summary> /// 受信データを解析し、それに対するコマンド(処理)を実行する. /// 現状受信スレッドの中で直接解析し、コマンドを実行している。 /// </summary> /// <param name="source"></param> /// <param name="buffer"></param> /// <param name="endPoint"></param> /// <returns></returns> public bool analyzePacket(UdpComponent source, System.Net.IPEndPoint fromEndPoint, byte[] buffer) { try { this.lastEndPoint = fromEndPoint; String request = Encoding.UTF8.GetString(buffer); fireReceivedDelegate(this.lastEndPoint.ToString(), request); RequestTokenizer tokenizer = new RequestTokenizer(request); String command = null; String data = null; int code = -1; // 順序規定なしのデータ取得. while (tokenizer.nextToken()) { switch (tokenizer.tokenType) { case RequestTokenizer.TokenType.COMMAND: command = tokenizer.token; break; case RequestTokenizer.TokenType.DATA: data = tokenizer.token; break; case RequestTokenizer.TokenType.NUMBER: code = Int32.Parse(tokenizer.token); break; } if (command != null && data != null && code == 0) { execute(fromEndPoint, command, data); command = null; data = null; } } } catch(Exception e) { LOGGER.error("failed to analyze received data", e); return false; } return true; }
private void initUdpComponent(int udpPort) { this.udpComponent = new UdpComponent(udpPort); this.udpComponent.receiveDelegate = this.analyzePacket; }