public void ReceiveHeaderCallback(IAsyncResult ar) { QsNetIOStateObject headerState = (QsNetIOStateObject)ar.AsyncState; int bytesRead = receiveSocket.EndReceive(ar); if (bytesRead > 0) { headerState.count += bytesRead; if (headerState.count < QsPackageHeader.headerBufferSize) receiveSocket.BeginReceive(header.headerBuffer, headerState.count, QsPackageHeader.headerBufferSize - headerState.count, 0, new AsyncCallback(ReceiveHeaderCallback), headerState); else { QsNetIOStateObject dataState = new QsNetIOStateObject(); data = new QsPackageData(header.GetDataLength()); receiveSocket.BeginReceive(data.dataBuffer, dataState.count, data.dataLength - dataState.count, 0, new AsyncCallback(ReceiveDataCallback), dataState); } } }
private void SendHeaderCallback(IAsyncResult ar) { QsNetIOStateObject headerState = (QsNetIOStateObject)ar.AsyncState; int bytesSend = sendSocket.EndSend(ar); if (bytesSend > 0) { headerState.count += bytesSend; if (headerState.count < QsPackageHeader.headerBufferSize) sendSocket.BeginSend(header.headerBuffer, headerState.count, QsPackageHeader.headerBufferSize - headerState.count, 0, new AsyncCallback(SendHeaderCallback), headerState); else { QsNetIOStateObject dataState = new QsNetIOStateObject(); sendSocket.BeginSend(data.dataBuffer, dataState.count, data.dataLength - dataState.count, 0, new AsyncCallback(SendDataCallback), dataState); } } }
public void Receive() { QsNetIOStateObject state = new QsNetIOStateObject(); receiveSocket.BeginReceive(state.buffer, state.count, QsPackageHeader.headerBufferSize - state.count, 0, new AsyncCallback(ReceiveHeaderCallback), state); }
public void Send() { QsNetIOStateObject state = new QsNetIOStateObject(); sendSocket.BeginSend(header.headerBuffer, state.count, QsPackageHeader.headerBufferSize - state.count, 0, new AsyncCallback(SendHeaderCallback), state); }