This project has moved. For the latest updates, please go here.

VB.NET - Buffer full TCP-Server

Jun 11, 2015 at 1:25 PM
Edited Jun 11, 2015 at 5:56 PM
Hey, i have a problem with TCP-Server.
I can send the input from microphone with a TCP-Client but the TCP-Server cannot play, because fast cames the error: "buffer full".
I have searched but i didn't found a solution and i have asked in two forums, one user recommended me to ask here.


Private Sub MainServer()
    Dim bytes(1024) As Byte
    Dim Received_Message As String = Nothing
    While True
        Dim client As TcpClient = TCP_Server.AcceptTcpClient()
        Dim MicrosoftADPCM_Codec As INetworkChatCodec = New MicrosoftADPCM()
        Dim stream As NetworkStream = client.GetStream

        waveOut = New WaveOut()
        waveProvider = New BufferedWaveProvider(MicrosoftADPCM_Codec.RecordFormat)

        Dim i As Int32 = stream.Read(bytes, 0, bytes.Length)
        While (i <> 0)

            Dim decoded As Byte() = MicrosoftADPCM_Codec.Decode(bytes, 0, i)
            waveProvider.AddSamples(decoded, 0, decoded.Length)

        End While
    End While
End Sub
    Dim TCP_Client As New TcpClient("IP", "PORT")
    Dim stream As Stream = TCP_Client.GetStream

    Call_Stream = stream
    Dim MicrosoftADPCM_Codec As INetworkChatCodec = New MicrosoftADPCM()
    selectedCodec = MicrosoftADPCM_Codec
    waveIn = New WaveIn()
    waveIn.BufferMilliseconds = 50
    waveIn.DeviceNumber = comboBoxInputDevices.SelectedIndex
    waveIn.WaveFormat = MicrosoftADPCM_Codec.RecordFormat

    AddHandler waveIn.DataAvailable, AddressOf waveIn_DataAvailable
Private Sub waveIn_DataAvailable(sender As Object, e As WaveInEventArgs)
    Dim encoded As Byte() = selectedCodec.Encode(e.Buffer, 0, e.BytesRecorded)
    Call_Stream.Write(encoded, 0, encoded.Length)
End Sub
Thank your for any replies.
Jun 12, 2015 at 4:54 PM
are you playing from the BufferedWaveprovider? If not it will just fill up and you'll get an exception as you are seeing here
Jun 16, 2015 at 3:29 PM
Hmm, that is all.
I think that:
refresh the bytes and playing.

What should I do? How i play right?
Jun 17, 2015 at 8:06 PM
you can still over-fill the buffer if you are receiving data too fast, or maybe if you have got your recording formats wrong. To see a working example of what you are trying to do, take a look at the code for the network chat demo in the NAudio demo application
Jun 18, 2015 at 1:52 PM
This code is from NAudio Network Chat, only in VB.NET and as TCP.
Therefore i asked.
Jun 18, 2015 at 3:14 PM
well for the buffer to fill up you are receiving audio faster than you are playing it, which is odd.
So main ways you can fix that are
  1. increase the buffer size, maybe it's just a transient issue
  2. throw away received audio when the buffer is looking full
Jun 23, 2015 at 3:23 PM
Thank you very much for your patience.
It was a problem in the while loop, but now works.
Jun 23, 2015 at 3:26 PM
great, glad you have it working now