Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // References
- Owin
- System
- System.Core
- Microsoft.CSharp
- Microsoft.AspNet.SignalR.Core
- Microsoft.Owin
- Microsoft.Owin.Cors
- Microsoft.Owin.Hosting
- // Server
- using System;
- using Microsoft.AspNet.SignalR;
- using Microsoft.Owin.Cors;
- using Microsoft.Owin.Hosting;
- using Owin;
- namespace Chat
- {
- public class Chat : Hub
- {
- public void Talk(string message)
- {
- Clients.All.Hear(message);
- }
- }
- public class Startup
- {
- public void Configuration(IAppBuilder app)
- {
- app.Map("/signalr", map =>
- {
- map.UseCors(CorsOptions.AllowAll);
- map.RunSignalR();
- });
- }
- }
- public class Program
- {
- static void Main(string[] args)
- {
- using (WebApp.Start<Startup>("http://172.27.241.196:8123/"))
- {
- Console.WriteLine("Server running at http://daheim:8123/");
- Console.ReadLine();
- }
- }
- }
- }
- // Client
- <script src="jquery-1.6.4.min.js"></script>
- <script src="jquery.signalR-2.0.0.min.js"></script>
- <script src="http://localhost:8123/signalr/hubs"></script>
- <script>
- $(function () {
- $.connection.hub.url = "http://localhost:8123/signalr";
- var chat = $.connection.chat;
- $.connection.hub.start()
- .done(function () {
- chat.server.talk("Yeah connected:D");
- });
- $('#mouth').keypress(function () {
- chat.server.talk($(this).val());
- });
- chat.client.hear = function (message) {
- $('#ear').text(message);
- };
- });
- </script>
- <input id="mouth" type="text">
- <div id="ear"></div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement