我無法將我的java應用程序連接到我的SignalR服務器。
服務器非常簡單,可以在這裏找到:
https://code.msdn.microsoft.com/windowsdesktop/Using-SignalR-in-WinForms-f1ec847bSignalR java無法連接到服務器
我可以連接,但我有我的Java客戶端的麻煩Web客戶端(JavaScript)的和Windows客戶端(C#)( https://github.com/SignalR/java-client)
這裏是我到目前爲止的代碼:
package javaapplication2;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import microsoft.aspnet.signalr.client.SignalRFuture;
import microsoft.aspnet.signalr.client.hubs.HubConnection;
import microsoft.aspnet.signalr.client.hubs.HubProxy;
public class JavaApplication2 {
public static void main(String[] args) throws IOException, InterruptedException, ExecutionException, TimeoutException
{
String ServerURI = "http://localhost:8080/signalr";
HubConnection Connection = new HubConnection(ServerURI);
HubProxy HubProxy = Connection.createHubProxy("MyHub");
HubProxy.on("AddMessage",() -> { System.out.println("Some message"); });
Connection.error(new ErrorCallback() {
@Override
public void onError(Throwable error) {
error.printStackTrace(); //<==SocketException
}
});
SignalRFuture<Void> con =Connection.start();
con.get();
}
}
更新
當我運行它,我得到一個「爲ExecutionException:java.net.SocketException異常:連接復位」
Exception in thread "main" java.util.concurrent.ExecutionException: java.net.SocketException: Connection reset
at microsoft.aspnet.signalr.client.SignalRFuture.get(SignalRFuture.java:112)
at microsoft.aspnet.signalr.client.SignalRFuture.get(SignalRFuture.java:102)
at javaapplication2.JavaApplication2.main(JavaApplication2.java:27)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:209)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:704)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:675)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1535)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at microsoft.aspnet.signalr.client.http.java.NetworkRunnable.run(NetworkRunnable.java:72)
at java.lang.Thread.run(Thread.java:745)
- 如果我把「localhost」的東西,不存在(如locahostX)我得到一個java .net.UnknownHostException
- 如果如果把「localhost」我的IP,我不事件得到一個異常...
- 所有的其他應用程序與兩個(或本地主機IP)
工作起初我以爲這是一個防火牆的問題,但它不是...
顯然我失去了一些東西... 任何想法?
感謝
不知道關於這個問題,但你曾嘗試使用帶有ILogger實例的HubConnection構造函數重載嗎?似乎自動傳輸選擇(協商)不起作用,並且內部SignalR日誌可能對此有所幫助。嘗試一下併發布日誌... –