我已经编写了几个SignalR / C#原型,它们都可以在Windows上运行。这是一个非常简单的SignalR客户端,无法与Mono / Nginx服务器通信。问题是当我让Nginx运行我的单声道服务器代码然后尝试与客户端通信时。尝试建立连接时出现异常。
所有内容都在localhost上运行:9001
有人看到我的方法有什么问题吗?
服务器代码:
using Microsoft.AspNet.SignalR;
namespace SignalRMonoTesting
{
public class ChatHub : Hub
{
public void Send(string name, string message)
{
// Call the broadcastMessage method to update clients.
Clients.All.broadcastMessage(name, message);
}
}
}
启动代码:
using Microsoft.AspNet.SignalR;
using Microsoft.Owin.Cors;
using Owin;
namespace SignalRMonoTesting
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
// Any connection or hub wire up and configuration should go here
app.MapSignalR();
// Branch the pipeline here for requests that start with "/signalr"
//app.Map("/signalr", map =>
//{
// // Setup the CORS middleware to run before SignalR.
// // By default this will allow all origins. You can
// // configure the set of origins and/or http verbs by
// // providing a cors options with a different policy.
// map.UseCors(CorsOptions.AllowAll);
// var hubConfiguration = new HubConfiguration
// {
// // You can enable JSONP by uncommenting line below.
// // JSONP requests are insecure but some older browsers (and some
// // versions of IE) require JSONP to work cross domain
// // EnableJSONP = true
// };
// // Run the SignalR pipeline. We're not using MapSignalR
// // since this branch already runs under the "/signalr"
// // path.
// hubConfiguration.EnableDetailedErrors = true;
// map.RunSignalR(hubConfiguration);
//});
}
}
}
客户代码:
<!DOCTYPE html>
<html>
<head>
<title>SignalR Simple Chat</title>
<style type="text/css">
.container {
background-color: #99CCFF;
border: thick solid #808080;
padding: 20px;
margin: 20px;
}
</style>
</head>
<body>
<div class="container">
<input type="text" id="message" />
<input type="button" id="sendmessage" value="Send" />
<input type="hidden" id="displayname" />
<ul id="discussion"></ul>
</div>
<!--Script references. -->
<!--Reference the jQuery library. -->
<script src="Scripts/jquery-1.6.4.min.js"></script>
<!--Reference the SignalR library. -->
<script src="Scripts/jquery.signalR-2.2.3.min.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="signalr/hubs"></script>
<!--Add script to update the page and send messages.-->
<script type="text/javascript">
$(function () {
// Declare a proxy to reference the hub.
var chat = $.connection.chatHub;
// Create a function that the hub can call to broadcast messages.
chat.client.broadcastMessage = function (name, message) {
// Html encode display name and message.
var encodedName = $('<div />').text(name).html();
var encodedMsg = $('<div />').text(message).html();
// Add the message to the page.
$('#discussion').append('<li><strong>' + encodedName
+ '</strong>: ' + encodedMsg + '</li>');
};
// Get the user name and store it to prepend to messages.
$('#displayname').val(prompt('Enter your name:', ''));
// Set initial focus to message input box.
$('#message').focus();
// Start the connection.
$.connection.hub.start().done(function () {
$('#sendmessage').click(function () {
// Call the Send method on the hub.
chat.server.send($('#displayname').val(), $('#message').val());
// Clear text box and reset focus for next comment.
$('#message').val('').focus();
});
});
});
</script>
</body>
</html>
抛出异常:
System.NotImplementedException: The method or operation is not implemented.
at System.Web.HttpResponseBase.BeginFlush (System.AsyncCallback callback, System.Object state) [0x00000] in <6e532a521c2242eaa28e5de0222d1e11>:0
at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncImpl (System.Func`3[T1,T2,TResult] beginMethod, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Object state, System.Threading.Tasks.TaskCreationOptions creationOptions) [0x00167] in <9bbab8f8a2a246e98480e70b0839fd67>:0
at System.Threading.Tasks.TaskFactory.FromAsync (System.Func`3[T1,T2,TResult] beginMethod, System.Action`1[T] endMethod, System.Object state, System.Threading.Tasks.TaskCreationOptions creationOptions) [0x00000] in <9bbab8f8a2a246e98480e70b0839fd67>:0
at System.Threading.Tasks.TaskFactory.FromAsync (System.Func`3[T1,T2,TResult] beginMethod, System.Action`1[T] endMethod, System.Object state) [0x00000] in <9bbab8f8a2a246e98480e70b0839fd67>:0
at Microsoft.Owin.Host.SystemWeb.CallStreams.OutputStream+<FlushAsync>d__2.MoveNext () [0x00057] in <cbdb620b45e24ba4960a309f8696d137>:0
--- End of stack trace from previous location where exception was thrown ---