public void SourceLoop(MediaQueue mediaQueue) { while (true) { try { var endPoint = new IPEndPoint(IPAddress.Any, udpPort); var udpClient = new UdpClient(endPoint) { Client = { ReceiveBufferSize = 1024 * 1024 } }; while (true) { var buffer = udpClient.Receive(ref endPoint); var chunk = new Chunk(buffer, buffer.Length); mediaQueue.Write(chunk); } } catch (Exception e) { logger.Error(e.Message); } } }
public void SourceLoop(MediaQueue mediaQueue) { while (true) { try { logger.Info($"Read from {httpUri}"); var request = (HttpWebRequest)WebRequest.Create(httpUri); var responseStream = ((HttpWebResponse)request.GetResponse()).GetResponseStream(); while (true) { var buffer = new byte[ReceiveSize * 4]; var receivedLength = 0; while (receivedLength < ReceiveSize * 2) { var length = responseStream.Read(buffer, receivedLength, ReceiveSize); if (length == 0) { throw new Exception("Socket was closed, returned 0 bytes"); } receivedLength += length; } var chunk = new Chunk(buffer, receivedLength); mediaQueue.Write(chunk); } } catch (Exception e) { logger.Error($"Lost connection to {httpUri}: {e.Message}"); Thread.Sleep(2000); } } }