I've found a real oddity which I can't find any reasoning or documentation for. If you run this code which starts a socket listening and then also starts an encoder, from this point forward you can't close the listening socket.
Dim backlog As Integer = 0
listenSocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
Dim hostIP As IPAddress = Dns.Resolve(IPAddress.Any.ToString()).AddressList(0)
Dim ep As IPEndPoint = New IPEndPoint(hostIP, 9000)
listenSocket.Bind(ep)
listenSocket.Listen(backlog)
Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero) 'Set to no sound device
Dim _Mixer As Integer = BassMix.BASS_Mixer_StreamCreate(44100, 2, BASSFlag.BASS_DEFAULT Or BASSFlag.BASS_MIXER_NONSTOP) 'Create a mixer
Bass.BASS_ChannelPlay(_Mixer, False) 'Play mixer
Dim _EncoderString As String = "ffmpeg.exe -loglevel -8 -f s16le -ac 2 -ar 44100 -i - -f adts -b:a 128k -c:a aac -"
Dim _EncoderContent As String = BassEnc.BASS_ENCODE_TYPE_AAC
_Encoder = BassEnc.BASS_Encode_Start(_Mixer, _EncoderString, BASSEncode.BASS_ENCODE_NOHEAD Or BASSEncode.BASS_ENCODE_FP_16BIT Or BASSEncode.BASS_ENCODE_LIMIT, Nothing, IntPtr.Zero)
If you open up Performance Monitor and go to the network tab you can see on the listening port that port 9000 will be open, but if you then try to close the socket:
listenSocket.Close()
It doesn't grey out and is still alive for connections, although those connections don't register and you can't send data to them. It's really odd.
If you try to close the socket and then close the encoder then it greys out in performance monitor as expected. I've tried the encoder using lame and ffmpeg, it's the same issue.
So what am I missing here? Why is the encoder having a hold over the socket?