InetClearQueue Example for Visual Basic

This is also the example for the InetQueueSize property.

' This example checks the size of computers in the send lists before it sends data to the remote
' computer. It uses the LEAD Capture Control for recording audio data. Refer to the LEAD Capture
’ Control documentation for an example of recording audio data

Private Sub LEADCap1_CapAudioData(ByVal pData As Variant, ByVal lBytesRecorded As Long, ByVal iIndex As Integer)

   Dim i As Integer
   Dim qSize As Long
   Dim RasterVar1 As LEADRasterVariant
   Dim RasterVar2 As LEADRasterVariant
   Dim pExtraData As Variant

   ' check the queue size of all computers in SendList
   ' this is the list of computers that are connected to us
   For i = 0 To LEADServer.SendListNum - 1
      qSize = LEADServer.InetQueueSize(LEADServer.SendList(i))
      ' clear queue there is more than 10 seconds worth of sound data
      If qSize > (LEADCap1.CapWaveAvgBytesPerSec(CAP_AUDIO_RECORD) * 10) Then
         LEADServer.InetClearQueue(LEADServer.SendList(i))
      End If
   Next


   vExtraData = LEADCap1.CapWaveExtraData(CAP_AUDIO_RECORD)

   If VarType(vExtraData) = vbArray Or vbByte Then
      RasterVar1.Type = VALUE_ARRAY_BYTE
      size = UBound(vExtraData) - LBound(vExtraData) + 1
      Dim LArray(size) As Byte
      LArray = vExtraData
      RasterVar1.ItemCount = size
      For i = 0 To i < size - 1 Step 1
         RasterVar1.ShortItemValue(i) = Array(i)
      Next i

   ElseIf VarType(vExtraData) = vbString Then
      RasterVar1.Type = VALUE_STRING
      RasterVar1.StringValue = vExtraData

   Else
      Exit Sub
   End If

   If VarType(pData) = vbArray Or vbByte Then
      RasterVar2.Type = VALUE_ARRAY_BYTE
      size = UBound(pData) - LBound(pData) + 1
      Dim LArray(size) As Byte
      LArray = pData
      RasterVar2.ItemCount = size
      For i = 0 To i < size - 1 Step 1
         RasterVar2.ShortItemValue(i) = Array(i)
      Next i

   ElseIf VarType(pData) = vbString Then
      RasterVar2.Type = VALUE_STRING
      RasterVar2.StringValue = pData

   Else
      Exit Sub
   End If

   'send data to all clients in the server send list
   If (LEADServer.SendListNum > 0) Then
      LEADServer.InetSendSound LEADCap1.CapWaveFormatTag(CAP_AUDIO_RECORD), LEADCap1.CapWaveChannels(CAP_AUDIO_RECORD), LEADCap1.CapWaveSamplesPerSec(CAP_AUDIO_RECORD), _
LEADCap1.CapWaveAvgBytesPerSec(CAP_AUDIO_RECORD), LEADCap1.CapWaveBlockAlign(CAP_AUDIO_RECORD), LEADCap1.CapWaveBitsPerSample(CAP_AUDIO_RECORD), _
LEADCap1.CapWaveExtraSize(CAP_AUDIO_RECORD), RasterVar1, RasterVar2, lBytesRecorded
   End If

   ' check the queue size of all computers in SendList
   ' this is the list of computers that we are connected to
   For i = 0 To LEADServer.SendListNum - 1
      qSize = LEADClient.InetQueueSize(LEADClient.SendList(i))
      ' clear queue there is more than 10 seconds worth of sound data
      If qSize > (LEADCap1.CapWaveAvgBytesPerSec(CAP_AUDIO_RECORD) * 10) Then
         LEADClient.InetClearQueue (LEADClient.SendList(i))
      End If
   Next

   'send data to all servers in the client send list
   If (LEADClient.SendListNum > 0) Then
      LEADClient.InetSendSound LEADCap1.CapWaveFormatTag(CAP_AUDIO_RECORD), LEADCap1.CapWaveChannels(CAP_AUDIO_RECORD), LEADCap1.CapWaveSamplesPerSec(CAP_AUDIO_RECORD), _
LEADCap1.CapWaveAvgBytesPerSec(CAP_AUDIO_RECORD), LEADCap1.CapWaveBlockAlign(CAP_AUDIO_RECORD), LEADCap1.CapWaveBitsPerSample(CAP_AUDIO_RECORD), _
LEADCap1.CapWaveExtraSize(CAP_AUDIO_RECORD), RasterVar1, RasterVar2, lBytesRecorded
   End If
End Sub