using System; using System.Collections.Generic; using System.Linq; using System.Web; using Microsoft.AspNet.SignalR.Hubs; namespace SignalR_mvc { public class ChatHub : Hub { public void Send(string message) { // Call the broadcastMessage method to update clients. Clients.All.broadcastMessage(message); } } }
@{ ViewBag.Title = "Index"; } <h2>Index</h2> <div class="container"> <input type="text" id="message" /> <input type="button" id="sendmessage" value="Send" /> <input type="hidden" id="displayname" /> <ul id="discussion"> </ul> </div> <script src="Scripts/jquery-1.6.4.min.js" ></script> <script src="Scripts/jquery.signalR-1.0.0-rc1.js"></script> <script src="/signalr/hubs"></script> <script type="text/javascript"> $(function () { // Declare a proxy to reference the hub. var chat = $.connection.chatHub; // Create a function that the hub can call to broadcast messages. chat.client.broadcastMessage = function (message) { $('#discussion').append('<li>' + message + '</li>'); }; // Start the connection. $.connection.hub.start(); $('#sendmessage').click(function () { // Html encode display name and message. var encodedMsg = $('<div />').text($('#message').val()).html(); // Call the Send method on the hub. chat.server.send(encodedMsg); // Clear text box and reset focus for next comment. }); }); </script>
@{ ViewBag.Title = "Index"; } <h2>Index</h2> <div class="container"> <ul id="discussion"> </ul> </div> <script src="Scripts/jquery-1.6.4.min.js" ></script> <script src="Scripts/jquery.signalR-1.0.0-rc1.js"></script> <script src="/signalr/hubs"></script> <script type="text/javascript"> $(function () { // Declare a proxy to reference the hub. var chat = $.connection.chatHub; // Create a function that the hub can call to broadcast messages. chat.client.broadcastMessage = function (message) { $('#discussion').append('<li>' + message + '</li>'); }; // Start the connection. $.connection.hub.start(); }); </script>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)