Setup:SignalR khách hàng được kết nối lại sau khi khởi động lại Owin, nhưng thông điệp không được công bố
- SignalRServer console app: Microsoft.AspNet.SignalR.SelfHost v2.0.3
- SignalRClient console app: Microsoft .AspNet.SignalR.Client v2.0.3
- NET 4.5.1
tôi làm như sau:
- Hit nhập trên máy khách, một thông báo được nhận tại server và trên máy khách một lần nữa
- Vứt bỏ các máy chủ bằng cách nhấn phím bất kỳ trong máy chủ giao diện điều khiển
- Khởi động lại máy chủ bằng cách đánh phím bất kỳ trong máy chủ giao diện điều khiển
- khách hàng được kết nối lại
- Hit nhập vào khách hàng, nhận được tin nhắn ở máy chủ, nhưng không bao giờ đạt đến khách hàng một lần nữa
Tôi hy vọng tin nhắn sẽ được nhận lại tại máy khách. Tôi nghi ngờ nó có một cái gì đó để làm với việc tự lưu trữ, kể từ khi tôi đã cố gắng để chạy các khách hàng chống lại cùng một trung tâm trong một ứng dụng web chạy IIS với thành công.
Bất kỳ ý tưởng nào?
Cập nhật: nếu quá trình bảng điều khiển máy chủ bị giết và khởi động lại, nó có thể kết nối lại và truy xuất lại thư.
mã máy chủ
using System;
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR;
using Microsoft.Owin.Hosting;
using Owin;
namespace SignalRServer
{
internal class Program
{
private static void Main(string[] args)
{
const string url = "http://localhost:8081";
while (true)
{
using (WebApp.Start<Startup>(url))
{
Console.WriteLine("Server running on {0}. Hit any key to stop.", url);
Console.ReadLine();
}
Console.WriteLine("Server stopped");
Console.WriteLine("Hit any key to restart, Esc to exit");
ConsoleKeyInfo ki = Console.ReadKey(true);
if (ki.Key == ConsoleKey.Escape)
return;
}
}
}
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
public class AuthenticationHub : Hub
{
public void BroadcastMessageToAll(string message)
{
Clients.All.sendMessageToClient(message);
Console.WriteLine("sendMessageToClient: " + message);
}
public override Task OnConnected()
{
Console.WriteLine("OnConnected " + Context.ConnectionId);
return base.OnConnected();
}
public override Task OnReconnected()
{
Console.WriteLine("OnReconnected " + Context.ConnectionId);
return base.OnReconnected();
}
public override Task OnDisconnected()
{
Console.WriteLine("OnDisconnected " + Context.ConnectionId);
return base.OnReconnected();
}
}
}
Khách hàng đang
using System;
using Microsoft.AspNet.SignalR.Client;
namespace SignalRClient
{
class Program
{
static void Main(string[] args)
{
while (true)
{
var hubConnection = new HubConnection("http://localhost:8081/signalr/hubs");
hubConnection.Closed +=() => Console.WriteLine("Closed");
hubConnection.StateChanged += e => Console.WriteLine("StateChanged: " + e.OldState + " " + e.NewState);
var hubProxy = hubConnection.CreateHubProxy("AuthenticationHub");
hubProxy.On<string>("sendMessageToClient",
info => Console.WriteLine("sendMessageToClient received: " + info));
hubConnection.Start();
Console.WriteLine("Client started - hit Enter to send a message - ESC to stop");
Console.ReadKey();
while (true)
{
var keyInfo = Console.ReadKey(true);
if (keyInfo.Key == ConsoleKey.Escape)
break;
var message = "Console client : " + DateTime.Now.ToString("HH:mm:ss-fff");
hubProxy.Invoke("BroadcastMessageToAll", message);
Console.WriteLine("Client sent BroadcastMessageToAll: " + message);
}
Console.WriteLine("Client stopping");
hubConnection.Stop();
Console.WriteLine("Client stopped - enter any key start again");
Console.ReadLine();
}
}
}
}
Tôi ước gì có thể giúp đỡ nhiều hơn, nhưng tôi sao chép máy chủ của bạn và mã khách hàng đúng nguyên văn thành hai giao diện điều khiển dự án ứng dụng. Sau khi cài đặt các gói NuGet cần thiết, tôi đã có thể khởi động lại ứng dụng máy chủ, yêu cầu khách hàng tự động kết nối lại và sau đó tiếp tục gửi và nhận tin nhắn sau đó. – halter73
Tôi đã cập nhật các bước để tái sản xuất chính xác hơn. Bạn nên khởi động lại chính ứng dụng giao diện điều khiển máy chủ, nhưng chính ứng dụng máy chủ SignalR. – Stian