0
我想投IAsyncResult.AsyncState類StateObject。但是由於AsyncState是Socket類型,所以它給出了一個轉換錯誤。我需要從結果中獲取字節數據。我剛開始一個服務器項目,我不熟悉這一點。無法施展IAsyncResult.AsyncState
public class StateObject
{
// Client socket.
public Socket workSocket = null;
// Size of receive buffer.
public const int BufferSize = 256;
// Receive buffer.
public byte[] buffer = new byte[BufferSize];
// Received data string.
public StringBuilder sb = new StringBuilder();
}
這是預先OnReceiveHandlerClass
private void Receive(IAsyncResult result)
{
StateObject ss = (StateObject)result.AsyncState;
......
}
謝謝..
朋友的問題是固定的... :-) – Sunil 2011-12-22 04:52:13
後的修復作爲一個答案,並接受它,所以程序員的後代可能難以倖免同樣的命運。 :) – Amy 2011-12-22 04:57:04
實際上這是我的錯誤,因爲我甚至不知道基礎知識。無論如何,我會發布錯誤。你說它可能有助於某人.... :-) – Sunil 2012-01-06 09:30:33