コード例 #1
0
        // Recieve callback opperation
        private void RecieveCallBack(IAsyncResult results)
        {
            SocketReceivedData DataReceiver = (SocketReceivedData)results.AsyncState;
            Socket             sct          = DataReceiver.Sct;

            int bytesRecieved = sct.EndReceive(results);

            // Checks for continued connection
            if (bytesRecieved > 0)
            {
                DataReceiver.Message += Encoding.ASCII.GetString(DataReceiver.DataStream);

                // Checks for end of file tag
                if (DataReceiver.Message.IndexOf(eof) == -1)
                {
                    // Continues Reading
                    sct.BeginReceive(DataReceiver.DataStream, 0, DataReceiver.DataSize, 0, new AsyncCallback(RecieveCallBack), DataReceiver);
                }
                // If end of file tag is found
                else
                {
                    // Runs message interpreter
                    MessageInterpreter(DataReceiver.Message);
                }
            }
            this.Recieve();
        }
コード例 #2
0
        // Sets up Async object recieve
        private void Recieve()
        {
            SocketReceivedData DataReciever = new SocketReceivedData();

            sct.BeginReceive(DataReciever.DataStream, 0, DataReciever.DataSize, 0, new AsyncCallback(RecieveCallBack), DataReciever);
        }