Sockets 使用套接字连接获取音频流
我是新的套接字编程,并想开发一个无线流应用程序使用套接字连接 流的URI类似于 将主机名设置为abc11.abcradio.com,端口设置为8256,并使用以下代码:Sockets 使用套接字连接获取音频流,sockets,windows-phone-8,audio-streaming,icecast,Sockets,Windows Phone 8,Audio Streaming,Icecast,我是新的套接字编程,并想开发一个无线流应用程序使用套接字连接 流的URI类似于 将主机名设置为abc11.abcradio.com,端口设置为8256,并使用以下代码: private async void Connect_Click(object sender, RoutedEventArgs e) { if (connected) { StatusText.Text = "Already connected"; return;
private async void Connect_Click(object sender, RoutedEventArgs e)
{
if (connected)
{
StatusText.Text = "Already connected";
return;
}
try
{
OutputView.Text = "";
StatusText.Text = "Trying to connect ...";
serverHost = new HostName(ServerHostname.Text);
// Try to connect to the
await clientSocket.ConnectAsync(serverHost, ServerPort.Text);
connected = true;
StatusText.Text = "Connection established" + Environment.NewLine;
dataReader = new DataReader(clientSocket.InputStream);
string receivedString = String.Empty;
uint numBytesRead;
try
{
while (true)
{
numBytesRead = await dataReader.LoadAsync(128);
StatusText.Text += numBytesRead.ToString();
}
}
catch (Exception)
{
// something went wrong in the socket connection
}
}
catch (Exception exception)
{
// If this is an unknown status,
// it means that the error is fatal and retry will likely fail.
if (SocketError.GetStatus(exception.HResult) == SocketErrorStatus.Unknown)
{
throw;
}
StatusText.Text = "Connect failed with error: " + exception.Message;
// Could retry the connection, but for this simple example
// just close the socket.
closing = true;
// the Close method is mapped to the C# Dispose
clientSocket.Dispose();
clientSocket = null;
}
}
}
我得了0分
abc11.abcradio.com:8256在浏览器中返回包含流信息的页面,而abc11.abcradio.com:8256/stream打开播放流的页面
如何获取流数据?该链接已失效,但您为什么不使用HTTP客户端来实现此目的?而且,我看不出你在这段代码中发出HTTP请求的地方。链接只是一个例子,而不是一个实际的链接。我认为通过套接字直接连接会更快…?我想象一个内置的HTTP客户端会比你自己的客户端快得多。不过这两种方式都无所谓,因为瓶颈将出现在网络和向您发送数据的服务器上。我使用内置HTTP客户端连接到URI,但我也想知道如何连接并从Icecast服务器获取音频数据……对不起,不,我已经多年没有做过任何C#了。我建议使用HTTP路由,询问如何使用标准HTTP客户机传输数据。这是一种适用于几乎所有使用HTTP客户机的人的方法,因此将有更广泛的知识。另外,您不想维护自己的HTTP客户端。如果响应是重定向,您将在上面的代码中执行什么操作?您是否阅读了RFC2616和相关的所有内容,并实现了您需要的功能?这有很多。