欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

signal自承载

发布时间:2025/6/15 编程问答 56 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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

总结

以上是生活随笔为你收集整理的signal自承载的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。