signal自承载
2019獨角獸企業重金招聘Python工程師標準>>>
?需要在nuget下載dll ? 命令
Install-Package Microsoft.AspNet.SignalR.SelfHost Install-Package Microsoft.Owin.Cors static void Main(string[] args) {string url = "http://localhost:8080";using (WebApp.Start(url)){Console.WriteLine("Server running on {0}", url);Console.ReadLine();} }?
class Startup {public void Configuration(IAppBuilder app){app.UseCors(CorsOptions.AllowAll);app.MapSignalR();} }Startup ? 名字不能變,Configuration也不能邊否則將會出現以下錯誤
System.EntryPointNotFoundException:“The following errors occurred while attempting to load
the app.
?- No assembly found containing an OwinStartupAttribute.
?- No assembly found containing a Startup or [AssemblyName].Startup class.”
?
簡單的服務端就這樣了
?
那么客戶端需要訪問訪問服務斷
Install-Package Microsoft.AspNet.SignalR.JS下載之后將在項目中出現jquery.js, ?signal.js文件,所以在項目中需要引用這倆文件, ? 其中還需要引用一個自承載的hub服務文件
<script src="Scripts/jquery-1.6.4.min.js"></script>
<script src="Scripts/jquery.signalR-2.2.2.min.js"></script>
<script src="http://localhost:8080/signalr/hubs"></script>
http://localhost:8080/signalr/hubs一定是要把自承載服務打開才能訪問的到的,?
<script type="text/javascript">$(function () { //Set the hubs URL for the connection$.connection.hub.url = "http://localhost:8080/signalr"; var chat = $.connection.myHub; // Create a function that the hub can call to broadcast messages.chat.client.addMessage = function (name, message) {//返回的數據, 根據參數來接收};// Start the connection.$.connection.hub.start().done(function () { $('#sendmessage').click(function () { chat.server.send($('#displayname').val(), $('#message').val(),'11'); //推送數據到服務器});});});</script>?
轉載于:https://my.oschina.net/objectboy/blog/1524646
總結
- 上一篇: redis入门(13)redis的事务p
- 下一篇: 用python创建数据库监控平台(3)安