Mam aplikację konsoli, która jest serwerem signalR na moim komputerze.Czy możliwe jest połączenie z serwerem klienta signalR na innym komputerze?
Mam stronę html, która jest klientem signalR w Internecie. Ale próbuję połączyć się z serwerem, ale mam zły błąd 400 żądania. Jeśli serwer nie działa, mam kolejną odpowiedź.
Możliwe jest, czy klient signalR ma podłączyć serwer na PC?
(Przepraszam za mój angielski)
Moja strona
<input type="text" id="msg" value=" " />
<input type="button" id="send" value="send" />
<ul id="message">
</ul>
<script src="Scripts/jquery-1.6.4.min.js"></script>
<script src="Scripts/jquery.signalR-1.1.2.min.js"></script>
<script>
$(function() {
jQuery.support.cors = true;
// Open a connection to the remote server
var connection = $.hubConnection('http://MyIpAddress:8080');
var chat = connection.createHubProxy('chat');
chat.on('send', function (message) {
$('#message').append('<li>' + message + '</li>');
});
// Turn logging on so we can see the calls in the browser console
connection.logging = true;
connection.start().done(function() {
$('#send').click(function() {
chat.invoke('send', $('#msg').val());
});
});
});
</script>
Mój kod Server
using Microsoft.Owin.Hosting;
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
//Install-Package Microsoft.Owin.Hosting -pre
//Install-Package Microsoft.Owin.Host.HttpListener -pre
namespace TestServer
{
class Program
{
static void Main(string[] args)
{
LocalIPAddress();
string url = "http://localhost:8080";
using (WebApplication.Start<Startup>(url))
{
Console.WriteLine("Server running on {0}", url);
Console.ReadLine();
}
}
}
}
Startup.cs
using Microsoft.AspNet.SignalR;
using Owin;
namespace TestServer
{
public class Startup
{
// This method name is important
public void Configuration(IAppBuilder app)
{
var config = new HubConfiguration
{
EnableCrossDomain = true
};
app.MapHubs(config);
}
}
}
Chat.cs
using Microsoft.AspNet.SignalR;
using System;
using System.Threading.Tasks;
namespace TestServer.Hubs
{
public class Chat : Hub
{
public override Task OnConnected()
{
Console.WriteLine("OnConnected " + Context.ConnectionId);
return base.OnConnected();
}
public void Send(string message)
{
Console.WriteLine(string.Format("Receive: {0} by {1} ", message, Context.ConnectionId));
Clients.All.send(message);
}
}
}
Zawsze pokazuj swój kod. Trudno jest odpowiedzieć na pytanie, które musi zawierać założenia na temat tego, co "zrobiłeś". – davidfowl
ich dokumenty sugerują, że nie używasz "jQuery.support.cors = true;" http://www.asp.net/signalr/overview/guide-to-the-api/hubs-api-guide-javascript-client#configureconnection (trzeba nieco przewinąć w miejscu, w którym znajduje się link na stronie) – Jon