Created
November 29, 2010 08:42
-
-
Save noqisofon/719738 to your computer and use it in GitHub Desktop.
受信が終了したときに呼び出される感じ。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// 受信が終了したときに呼び出されます。 | |
/// </summary> | |
/// <param name="ar"></param> | |
private void asyncReceiverCallback(IAsyncResult ar) { | |
UDPRecord record = (UDPRecord)ar.AsyncState; | |
byte[] received_bytes = record.client.EndReceive( ar, ref record.endpoint ); | |
record.client.Close(); | |
string result_data = Encoding.UTF8.GetString( received_bytes ); | |
/* | |
* result_data は XML 文字列ですが、そのままでは読みにくいので、 | |
* 論理的 DOM 構造に変換します。 | |
*/ | |
XMLDocumentConvertor convertor = new XMLDocumentConvertor(); | |
XmlDocument result_document = convertor.convert( result_data ); | |
XmlNode result = result_document.SelectSingleNode( "/response/result" ); | |
XmlAttribute status_attr = result.Attributes["status"]; | |
int status = status_attr == null ? -1 : Convert.ToInt32( status_attr.Value ); | |
// | |
// TODO: | |
// status で判別して何かする。 | |
// | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment