我有以下问题:
我有一个作为SignalR服务器运行的WPF应用程序和一些使用我用xamarin studio构建的Android应用程序的移动设备。
这个Android应用程序包含我的SignalR客户端。
我已经运行这个配置超过一年了,一切正常。
但是在上一次我遇到从客户端连接到服务器的问题。
在我启动Android应用程序之后,我尝试连接到服务器,并且第一次连接尝试几乎每次都会进入超时状态。如果第一次尝试失败,我会进行第二次连接尝试并立即连接。
我没有对我的服务器或客户端代码进行任何更改。我改变的唯一一件事就是从Xamarin Studio到Visual Studio 2015,现在包括Xamarin开发工具。
这基本上是我的客户代码:
public IHubProxy HubProxy1 { get; set; }
public HubConnection Connection1 { get; set; }
public async void Connect1Async()
{
Connection1 = new HubConnection ("http://192.168.41.220:8080/signalr");
Connection1.Closed += Connection1_Closed;
Connection1.Reconnected += Connection1_Reconnected;
Context context = this;
HubProxy1 = Connection1.CreateHubProxy ("MyHub");
HubProxy1.On<string, string, ObservableCollection<string>> ("ReceiveLoginAccepted", (displayname, userid, authorizations) => RunOnUiThread (() => ReceiveLoginAccepted (displayname, userid, authorizations)));
ServicePointManager.DefaultConnectionLimit = 10;
try {
await Connection1.Start ();
}
catch (Exception ex) {
MainActivity.Log(ex.ToString());
return;
}
}
这就是我的服务器代码:
public IDisposable SignalR { get; set; }
private void StartServer()
{
SignalR = WebApp.Start(http://localhost:8080");
}
然后我有一个startupClass:
class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseCors(CorsOptions.AllowAll);
app.MapSignalR();
}
}
和我的中心:
public class MyHub : Hub
{
internal static void ServerSend(string name, string message)
{
IHubContext context = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
context.Clients.All.addMessage(name, message);
context.Clients.All.Startsignal();
context.Clients.All.Alive();
}
}
以下是错误日志:
System.TimeoutException: Transport timed out trying to connect
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:113
at CEN40.MainActivity+<Connect1Async>d__105.MoveNext () [0x00504] in D:\_GitArbeitskopien\Cordenka\src\App\CEN40\CEN40\MainActivity.cs:2127
如果您需要更多信息,请与我们联系!!!