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
- 下一篇: web常见几种处理图标方法 【转】