You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
1.1 KiB

  1. using Microsoft.AspNet.SignalR;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Web;
  6. namespace DefenseWeb.Signalr
  7. {
  8. public class codingChatHub : Hub
  9. {
  10. // http://stackoverflow.com/questions/11155064/signalr-signalr-hubs-404-not-found
  11. // Fix cannot find ~/SignalR/hub
  12. public void Hello(string name)
  13. {
  14. // 這邊會傳入 name 參數
  15. // 呼叫所有連線狀態中頁面上的 javascript function => hello
  16. // 透過 server 端呼叫 client 的 javascript function
  17. // string message = " 歡迎使用者 " + name + " 加入聊天室 ";
  18. // Clients.All.hello(message);
  19. }
  20. public void SendMessage(string name, string message)
  21. {
  22. // 這邊會傳入 name 和 message 參數
  23. // 並且會呼叫所有連線狀態中頁面上的 javascript function => sendAllMessage
  24. // 透過 server 端呼叫 client 的 javascript function
  25. message = name + ":" + message;
  26. Clients.All.sendAllMessge(message);
  27. }
  28. }
  29. }