Exemplo n.º 1
0
 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);
         }
     }
 }
Exemplo n.º 2
0
 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);
         }
     }
 }
Exemplo n.º 3
0
 public void Receive()
 {
     QsNetIOStateObject state = new QsNetIOStateObject();
     receiveSocket.BeginReceive(header.headerBuffer, state.count, QsPackageHeader.headerBufferSize - state.count, 0, new AsyncCallback(ReceiveHeaderCallback), state);
 }
Exemplo n.º 4
0
 public void Send()
 {
     QsNetIOStateObject state = new QsNetIOStateObject();
     sendSocket.BeginSend(header.headerBuffer, state.count, QsPackageHeader.headerBufferSize - state.count, 0, new AsyncCallback(SendHeaderCallback), state);
 }