{"id":36935,"date":"2018-08-23T13:41:46","date_gmt":"2018-08-23T20:41:46","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/webdev\/?p=14985"},"modified":"2018-08-23T13:41:46","modified_gmt":"2018-08-23T20:41:46","slug":"asp-net-core-2-2-0-preview1-signalr-java-client","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/asp-net-core-2-2-0-preview1-signalr-java-client\/","title":{"rendered":"ASP.NET Core 2.2.0-preview1: SignalR Java Client"},"content":{"rendered":"<p><em>This post was authored by <a href=\"https:\/\/twitter.com\/MikaelM_12\">Mikael Mengistu<\/a>.<\/em><\/p>\n<p>In ASP.NET Core 2.2 we are introducing a Java Client for SignalR. The first preview of this new client is available now. This client supports connecting to an ASP.NET Core SignalR Server from Java code, including Android apps.<\/p>\n<p>The API for the Java client is very similar to that of the already existing .NET and JavaScript clients but there are some important differences to note.<\/p>\n<p>The HubConnection is initialized the same way, with the <code>HubConnectionBuilder<\/code> type.<\/p>\n<div class=\"sourceCode\" id=\"cb1\">\n<pre class=\"sourceCode java\"><code class=\"sourceCode java\"><a id=\"cb1-1\" class=\"sourceLine\"><\/a>HubConnection hubConnection = <span class=\"kw\">new<\/span> <span class=\"fu\">HubConnectionBuilder<\/span>()\n<a id=\"cb1-2\" class=\"sourceLine\"><\/a>        .<span class=\"fu\">withUrl<\/span>(<span class=\"st\">\"www.example.com\/myHub\"<\/span>)\n<a id=\"cb1-3\" class=\"sourceLine\"><\/a>        .<span class=\"fu\">configureLogging<\/span>(LogLevel.<span class=\"fu\">Information<\/span>)\n<a id=\"cb1-4\" class=\"sourceLine\"><\/a>        .<span class=\"fu\">build<\/span>();<\/code><\/pre>\n<\/div>\n<p>Just like in the .NET client, we can send an invocation using the send method.<\/p>\n<div class=\"sourceCode\" id=\"cb2\">\n<pre class=\"sourceCode java\"><code class=\"sourceCode java\"><a id=\"cb2-1\" class=\"sourceLine\"><\/a>hubConnection.<span class=\"fu\">send<\/span>(<span class=\"st\">\"Send\"<\/span>, input);<\/code><\/pre>\n<\/div>\n<p>Handlers for server invocations can be registered using the <code>on<\/code> method. One major difference here is that the argument types must be specified as parameters, due to differences in how Java handles generics.<\/p>\n<div class=\"sourceCode\" id=\"cb3\">\n<pre class=\"sourceCode java\"><code class=\"sourceCode java\"><a id=\"cb3-1\" class=\"sourceLine\"><\/a>hubConnection.<span class=\"fu\">on<\/span>(<span class=\"st\">\"Send\"<\/span>, (message) -&gt; {\n<a id=\"cb3-2\" class=\"sourceLine\"><\/a>      <span class=\"co\">\/\/ Your logic here<\/span>\n<a id=\"cb3-3\" class=\"sourceLine\"><\/a>}, <span class=\"bu\">String<\/span>.<span class=\"fu\">class<\/span>);<\/code><\/pre>\n<\/div>\n<p><strong>Installing the Java Client<\/strong><\/p>\n<p>If you\u2019re using Gradle you can add the following line to your <code>build.gradle<\/code> file:<\/p>\n<pre class=\"gradle\"><code>implementation 'com.microsoft.aspnet:signalr:0.1.0-preview1-35029'<\/code><\/pre>\n<p>If you\u2019re using Maven you can add the following lines to the dependencies section of your <code>pom.xml<\/code> file:<\/p>\n<div class=\"sourceCode\" id=\"cb2\">\n<pre class=\"sourceCode xml\"><code class=\"sourceCode xml\"><a id=\"cb2-1\" class=\"sourceLine\"><\/a><span class=\"kw\">&lt;dependency&gt;<\/span>\n<a id=\"cb2-2\" class=\"sourceLine\"><\/a>  <span class=\"kw\">&lt;groupId&gt;<\/span>com.microsoft.aspnet<span class=\"kw\">&lt;\/groupId&gt;<\/span>\n<a id=\"cb2-3\" class=\"sourceLine\"><\/a>  <span class=\"kw\">&lt;artifactId&gt;<\/span>signalr<span class=\"kw\">&lt;\/artifactId&gt;<\/span>\n<a id=\"cb2-4\" class=\"sourceLine\"><\/a>  <span class=\"kw\">&lt;version&gt;<\/span>0.1.0-preview1-35029<span class=\"kw\">&lt;\/version&gt;<\/span>\n<a id=\"cb2-5\" class=\"sourceLine\"><\/a><span class=\"kw\">&lt;\/dependency&gt;<\/span><\/code><\/pre>\n<\/div>\n<p>For a complete sample, see <a href=\"https:\/\/github.com\/aspnet\/SignalR-samples\/tree\/master\/AndroidJavaClient\">https:\/\/github.com\/aspnet\/SignalR-samples\/tree\/master\/AndroidJavaClient<\/a><\/p>\n<p>This is an early preview release of the Java client so there are many features that are not yet supported. We plan to close all these gaps before the RTM release:<\/p>\n<ul>\n<li>Only primitive types can be accepted as parameters and return types.<\/li>\n<li>The APIs are synchronous.<\/li>\n<li>Only the \u201cSend\u201d call type is supported at this time, \u201cInvoke\u201d and streaming return values are not supported.<\/li>\n<li>The client does not currently support the Azure SignalR Service.<\/li>\n<li>Only the JSON protocol is supported.<\/li>\n<li>Only the WebSockets transport is supported.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This post was authored by Mikael Mengistu. In ASP.NET Core 2.2 we are introducing a Java Client for SignalR. The first preview of this new client is available now. This client supports connecting to an ASP.NET Core SignalR Server from Java code, including Android apps. The API for the Java client is very similar to [&hellip;]<\/p>\n","protected":false},"author":1233,"featured_media":21397,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[197,7509],"tags":[4,7343,147,7412,7436,7268],"class_list":["post-36935","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aspnet","category-aspnetcore","tag-net","tag-publish","tag-visual-studio","tag-visual-studio-2012","tag-visual-studio-2013","tag-web"],"acf":[],"blog_post_summary":"<p>This post was authored by Mikael Mengistu. In ASP.NET Core 2.2 we are introducing a Java Client for SignalR. The first preview of this new client is available now. This client supports connecting to an ASP.NET Core SignalR Server from Java code, including Android apps. The API for the Java client is very similar to [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/36935","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/1233"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=36935"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/36935\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/21397"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=36935"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=36935"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=36935"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}