Skip to content

Instantly share code, notes, and snippets.

@noqisofon
Created November 29, 2010 08:42
Show Gist options
  • Save noqisofon/719738 to your computer and use it in GitHub Desktop.
Save noqisofon/719738 to your computer and use it in GitHub Desktop.
受信が終了したときに呼び出される感じ。
/// <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