6

I've got a couple SignalR basic demos working locally (chat, etc.) and I understand pushing to the server then having it broadcast to all connected clients.

My question is how might I utilize SignalR to "stream" data to the client. For example, seen examples in NodeJS/Socket.IO utilizing Twitters streaming API.

Are there any SignalR streaming examples out there? How might this work?

4

2 に答える 2

11

SignalR.Samplesプロジェクトのサンプルを見てください。そこにストリーミングサンプルがあります。

サーバー側の接続:

namespace SignalR.Samples.Streaming
{
    public class Streaming : PersistentConnection
    {
    }
}

ストリームを生成するコード

ThreadPool.QueueUserWorkItem(_ =>
{
    var connection = Connection.GetConnection<Streaming.Streaming>();
    while (true)
    {
        connection.Broadcast(DateTime.Now.ToString());
        Thread.Sleep(2000);
    }
});

クライアントサイドコード

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <script src="../Scripts/jquery-1.6.2.min.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.signalR.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            var connection = $.connection('Streaming.ashx');

            connection.received(function (data) {
                $('#messages').append('<li>' + data + '</li>');
            });

            connection.start();
        });
    </script>
</head>
<body>
    <ul id="messages">
    </ul>
</body>
</html>
于 2011-11-17T04:42:20.257 に答える
1

SignalRを使用して、昔ながらの方法でHTTP経由でダウンロードを開始するようにクライアントに指示しないのはなぜですか?またはStream、.NETに関して別の方法で使用していますか?

外部イベントをブロードキャストすることだけを意味する場合、クライアントの1つが、中継するために興味深いデータイベントを送信している他のサービスになることができないということは何もありません。

于 2011-11-16T14:34:16.590 に答える