├── README.md └── Src ├── SignalR Android ├── .gitattributes ├── .gitignore ├── .idea │ ├── compiler.xml │ ├── copyright │ │ └── profiles_settings.xml │ ├── gradle.xml │ ├── misc.xml │ ├── modules.xml │ └── runConfigurations.xml ├── README.md ├── SimpleSignalRClient-master.iml ├── SimpleSignalRClient.iml ├── app │ ├── .gitignore │ ├── app.iml │ ├── build.gradle │ ├── libs │ │ ├── gson-2.3.1.jar │ │ ├── signalr-client-sdk-android.jar │ │ └── signalr-client-sdk.jar │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── simplesignalrclient │ │ │ └── ApplicationTest.java │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── simplesignalrclient │ │ │ ├── CustomMessage.java │ │ │ ├── MainActivity.java │ │ │ └── SignalRService.java │ │ └── res │ │ ├── layout │ │ └── activity_main.xml │ │ ├── menu │ │ └── menu_main.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle └── SignalR Server ├── .vs └── config │ └── applicationhost.config ├── SignalRChat.sln ├── SignalRChat ├── ChatHub.cs ├── Default.html ├── Properties │ ├── AssemblyInfo.cs │ └── PublishProfiles │ │ ├── SignalR.pubxml │ │ └── SignalR.pubxml.user ├── Scripts │ ├── jquery-1.6.4-vsdoc.js │ ├── jquery-1.6.4.js │ ├── jquery-1.6.4.min.js │ ├── jquery.signalR-2.0.0.js │ └── jquery.signalR-2.0.0.min.js ├── SignalRChat.csproj ├── SignalRChat.csproj.user ├── Startup.cs ├── Web.Debug.config ├── Web.Release.config ├── Web.config ├── bin │ ├── Microsoft.AspNet.SignalR.Core.dll │ ├── Microsoft.AspNet.SignalR.Core.xml │ ├── Microsoft.AspNet.SignalR.SystemWeb.dll │ ├── Microsoft.AspNet.SignalR.SystemWeb.xml │ ├── Microsoft.Owin.Host.SystemWeb.dll │ ├── Microsoft.Owin.Host.SystemWeb.xml │ ├── Microsoft.Owin.Security.dll │ ├── Microsoft.Owin.Security.xml │ ├── Microsoft.Owin.dll │ ├── Microsoft.Owin.xml │ ├── Microsoft.Web.Infrastructure.dll │ ├── Newtonsoft.Json.dll │ ├── Newtonsoft.Json.xml │ ├── Owin.dll │ ├── SignalRChat.dll │ ├── SignalRChat.dll.config │ └── SignalRChat.pdb ├── obj │ ├── Debug │ │ ├── DesignTimeResolveAssemblyReferencesInput.cache │ │ ├── SignalRChat.csproj.FileListAbsolute.txt │ │ ├── SignalRChat.dll │ │ ├── SignalRChat.pdb │ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs │ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs │ │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs │ └── Release │ │ ├── DesignTimeResolveAssemblyReferencesInput.cache │ │ ├── Package │ │ └── PackageTmp │ │ │ ├── Default.html │ │ │ ├── Scripts │ │ │ ├── jquery-1.6.4.js │ │ │ ├── jquery-1.6.4.min.js │ │ │ ├── jquery.signalR-2.0.0.js │ │ │ └── jquery.signalR-2.0.0.min.js │ │ │ ├── Web.config │ │ │ ├── bin │ │ │ ├── Microsoft.AspNet.SignalR.Core.dll │ │ │ ├── Microsoft.AspNet.SignalR.SystemWeb.dll │ │ │ ├── Microsoft.Owin.Host.SystemWeb.dll │ │ │ ├── Microsoft.Owin.Security.dll │ │ │ ├── Microsoft.Owin.dll │ │ │ ├── Microsoft.Web.Infrastructure.dll │ │ │ ├── Newtonsoft.Json.dll │ │ │ ├── Owin.dll │ │ │ └── SignalRChat.dll │ │ │ └── packages.config │ │ ├── SignalRChat.csproj.FileListAbsolute.txt │ │ ├── SignalRChat.csprojResolveAssemblyReference.cache │ │ ├── SignalRChat.dll │ │ ├── SignalRChat.pdb │ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs │ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs │ │ ├── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs │ │ ├── TransformWebConfig │ │ ├── assist │ │ │ └── Web.config │ │ ├── original │ │ │ └── Web.config │ │ └── transformed │ │ │ └── Web.config │ │ └── _WPPLastBuildInfo.txt └── packages.config └── packages ├── Microsoft.AspNet.SignalR.2.0.0 ├── Microsoft.AspNet.SignalR.2.0.0.nupkg └── readme.txt ├── Microsoft.AspNet.SignalR.Core.2.0.0 ├── Microsoft.AspNet.SignalR.Core.2.0.0.nupkg └── lib │ └── net45 │ ├── Microsoft.AspNet.SignalR.Core.dll │ └── Microsoft.AspNet.SignalR.Core.xml ├── Microsoft.AspNet.SignalR.JS.2.0.0 ├── Microsoft.AspNet.SignalR.JS.2.0.0.nupkg └── content │ └── Scripts │ ├── jquery.signalR-2.0.0.js │ └── jquery.signalR-2.0.0.min.js ├── Microsoft.AspNet.SignalR.SystemWeb.2.0.0 ├── Microsoft.AspNet.SignalR.SystemWeb.2.0.0.nupkg └── lib │ └── net45 │ ├── Microsoft.AspNet.SignalR.SystemWeb.XML │ └── Microsoft.AspNet.SignalR.SystemWeb.dll ├── Microsoft.Owin.2.0.0 ├── Microsoft.Owin.2.0.0.nupkg └── lib │ ├── net40 │ ├── Microsoft.Owin.XML │ └── Microsoft.Owin.dll │ └── net45 │ ├── Microsoft.Owin.XML │ └── Microsoft.Owin.dll ├── Microsoft.Owin.Host.SystemWeb.2.0.0 ├── Microsoft.Owin.Host.SystemWeb.2.0.0.nupkg └── lib │ ├── net40 │ ├── Microsoft.Owin.Host.SystemWeb.dll │ └── Microsoft.Owin.Host.SystemWeb.xml │ └── net45 │ ├── Microsoft.Owin.Host.SystemWeb.dll │ └── Microsoft.Owin.Host.SystemWeb.xml ├── Microsoft.Owin.Security.2.0.0 ├── Microsoft.Owin.Security.2.0.0.nupkg └── lib │ └── net45 │ ├── Microsoft.Owin.Security.XML │ └── Microsoft.Owin.Security.dll ├── Microsoft.Web.Infrastructure.1.0.0.0 ├── Microsoft.Web.Infrastructure.1.0.0.0.nupkg └── lib │ └── net40 │ └── Microsoft.Web.Infrastructure.dll ├── Newtonsoft.Json.5.0.8 ├── Newtonsoft.Json.5.0.8.nupkg ├── lib │ ├── net20 │ │ ├── Newtonsoft.Json.dll │ │ └── Newtonsoft.Json.xml │ ├── net35 │ │ ├── Newtonsoft.Json.dll │ │ └── Newtonsoft.Json.xml │ ├── net40 │ │ ├── Newtonsoft.Json.dll │ │ └── Newtonsoft.Json.xml │ ├── net45 │ │ ├── Newtonsoft.Json.dll │ │ └── Newtonsoft.Json.xml │ ├── netcore45 │ │ ├── Newtonsoft.Json.dll │ │ └── Newtonsoft.Json.xml │ ├── portable-net40+sl4+wp7+win8 │ │ ├── Newtonsoft.Json.dll │ │ └── Newtonsoft.Json.xml │ └── portable-net45+wp80+win8 │ │ ├── Newtonsoft.Json.dll │ │ └── Newtonsoft.Json.xml └── tools │ └── install.ps1 ├── Owin.1.0 ├── Owin.1.0.nupkg └── lib │ └── net40 │ └── Owin.dll └── jQuery.1.6.4 ├── Content └── Scripts │ ├── jquery-1.6.4-vsdoc.js │ ├── jquery-1.6.4.js │ └── jquery-1.6.4.min.js ├── Tools ├── install.ps1 ├── jquery-1.6.4-vsdoc-para.js └── uninstall.ps1 └── jQuery.1.6.4.nupkg /README.md: -------------------------------------------------------------------------------- 1 | # SignalRAndroid 2 | SignalR Android Client Server sample 3 | -------------------------------------------------------------------------------- /Src/SignalR Android/.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /Src/SignalR Android/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | .DS_Store 6 | /build 7 | /captures 8 | -------------------------------------------------------------------------------- /Src/SignalR Android/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Src/SignalR Android/.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /Src/SignalR Android/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /Src/SignalR Android/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /Src/SignalR Android/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Src/SignalR Android/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /Src/SignalR Android/README.md: -------------------------------------------------------------------------------- 1 | # SimpleSignalRClient 2 | Simple SignalR Android Client 3 | 4 | #Code Example 5 | ``` 6 | 7 | private void startSignalR() { 8 | Platform.loadPlatformComponent(new AndroidPlatformComponent()); 9 | 10 | String serverUrl = "http://192.168.1.247:20583"; 11 | mHubConnection = new HubConnection(serverUrl); 12 | String SERVER_HUB_CHAT = "ChatHub"; 13 | mHubProxy = mHubConnection.createHubProxy(SERVER_HUB_CHAT); 14 | ClientTransport clientTransport = new ServerSentEventsTransport(mHubConnection.getLogger()); 15 | SignalRFuture signalRFuture = mHubConnection.start(clientTransport); 16 | 17 | try { 18 | signalRFuture.get(); 19 | } catch (InterruptedException | ExecutionException e) { 20 | Log.e("SimpleSignalR", e.toString()); 21 | return; 22 | } 23 | 24 | sendMessage("Hello from BNK!"); 25 | 26 | String CLIENT_METHOD_BROADAST_MESSAGE = "broadcastMessage"; 27 | mHubProxy.on(CLIENT_METHOD_BROADAST_MESSAGE, 28 | new SubscriptionHandler1() { 29 | @Override 30 | public void run(final CustomMessage msg) { 31 | final String finalMsg = msg.UserName + " says " + msg.Message; 32 | // display Toast message 33 | mHandler.post(new Runnable() { 34 | @Override 35 | public void run() { 36 | Toast.makeText(getApplicationContext(), finalMsg, Toast.LENGTH_SHORT).show(); 37 | } 38 | }); 39 | } 40 | } 41 | , CustomMessage.class); 42 | } 43 | 44 | ``` 45 | 46 | [SignalR server-side App - Microsoft's training documentation](http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr) 47 | -------------------------------------------------------------------------------- /Src/SignalR Android/SimpleSignalRClient-master.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Src/SignalR Android/SimpleSignalRClient.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Src/SignalR Android/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /Src/SignalR Android/app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /Src/SignalR Android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.0" 6 | 7 | defaultConfig { 8 | applicationId "com.example.simplesignalrclient" 9 | minSdkVersion 16 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | compile 'com.android.support:appcompat-v7:23.0.1' 25 | compile files('libs/gson-2.3.1.jar') 26 | compile files('libs/signalr-client-sdk-android.jar') 27 | compile files('libs/signalr-client-sdk.jar') 28 | } 29 | -------------------------------------------------------------------------------- /Src/SignalR Android/app/libs/gson-2.3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahmadaghazadeh/SignalRAndroid/6ab780949d93f0cc5c1d8e1c795b7715f5aaaa8e/Src/SignalR Android/app/libs/gson-2.3.1.jar -------------------------------------------------------------------------------- /Src/SignalR Android/app/libs/signalr-client-sdk-android.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahmadaghazadeh/SignalRAndroid/6ab780949d93f0cc5c1d8e1c795b7715f5aaaa8e/Src/SignalR Android/app/libs/signalr-client-sdk-android.jar -------------------------------------------------------------------------------- /Src/SignalR Android/app/libs/signalr-client-sdk.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahmadaghazadeh/SignalRAndroid/6ab780949d93f0cc5c1d8e1c795b7715f5aaaa8e/Src/SignalR Android/app/libs/signalr-client-sdk.jar -------------------------------------------------------------------------------- /Src/SignalR Android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Android\SDK/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /Src/SignalR Android/app/src/androidTest/java/com/example/simplesignalrclient/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.example.simplesignalrclient; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /Src/SignalR Android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 15 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Src/SignalR Android/app/src/main/java/com/example/simplesignalrclient/CustomMessage.java: -------------------------------------------------------------------------------- 1 | package com.example.simplesignalrclient; 2 | 3 | public class CustomMessage { 4 | public String UserName; 5 | public String Message; 6 | } 7 | -------------------------------------------------------------------------------- /Src/SignalR Android/app/src/main/java/com/example/simplesignalrclient/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.simplesignalrclient; 2 | 3 | import android.content.ComponentName; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.content.ServiceConnection; 7 | import android.os.Bundle; 8 | import android.os.IBinder; 9 | import android.support.v7.app.AppCompatActivity; 10 | import android.view.Menu; 11 | import android.view.MenuItem; 12 | import android.view.View; 13 | import android.widget.EditText; 14 | 15 | public class MainActivity extends AppCompatActivity { 16 | 17 | private final Context mContext = this; 18 | private SignalRService mService; 19 | private boolean mBound = false; 20 | 21 | @Override 22 | protected void onCreate(Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | setContentView(R.layout.activity_main); 25 | 26 | Intent intent = new Intent(); 27 | intent.setClass(mContext, SignalRService.class); 28 | bindService(intent, mConnection, Context.BIND_AUTO_CREATE); 29 | } 30 | 31 | @Override 32 | protected void onStop() { 33 | // Unbind from the service 34 | if (mBound) { 35 | unbindService(mConnection); 36 | mBound = false; 37 | } 38 | super.onStop(); 39 | } 40 | 41 | @Override 42 | public boolean onCreateOptionsMenu(Menu menu) { 43 | // Inflate the menu; this adds items to the action bar if it is present. 44 | getMenuInflater().inflate(R.menu.menu_main, menu); 45 | return true; 46 | } 47 | 48 | @Override 49 | public boolean onOptionsItemSelected(MenuItem item) { 50 | // Handle action bar item clicks here. The action bar will 51 | // automatically handle clicks on the Home/Up button, so long 52 | // as you specify a parent activity in AndroidManifest.xml. 53 | int id = item.getItemId(); 54 | 55 | //noinspection SimplifiableIfStatement 56 | if (id == R.id.action_settings) { 57 | return true; 58 | } 59 | 60 | return super.onOptionsItemSelected(item); 61 | } 62 | 63 | public void sendMessage(View view) { 64 | if (mBound) { 65 | // Call a method from the SignalRService. 66 | // However, if this call were something that might hang, then this request should 67 | // occur in a separate thread to avoid slowing down the activity performance. 68 | EditText editText = (EditText) findViewById(R.id.edit_message); 69 | EditText editText_Receiver = (EditText) findViewById(R.id.edit_receiver); 70 | if (editText != null && editText.getText().length() > 0) { 71 | String receiver = editText_Receiver.getText().toString(); 72 | String message = editText.getText().toString(); 73 | mService.sendMessage_To(receiver, message); 74 | } 75 | } 76 | } 77 | 78 | public void sendMessageAll(View view) { 79 | if (mBound) { 80 | // Call a method from the SignalRService. 81 | // However, if this call were something that might hang, then this request should 82 | // occur in a separate thread to avoid slowing down the activity performance. 83 | EditText editText = (EditText) findViewById(R.id.edit_message); 84 | EditText editText_Receiver = (EditText) findViewById(R.id.edit_receiver); 85 | if (editText != null && editText.getText().length() > 0) { 86 | String receiver = editText_Receiver.getText().toString(); 87 | String message = editText.getText().toString(); 88 | mService.sendMessage_To(receiver, message); 89 | } 90 | } 91 | } 92 | 93 | /** 94 | * Defines callbacks for service binding, passed to bindService() 95 | */ 96 | private final ServiceConnection mConnection = new ServiceConnection() { 97 | 98 | @Override 99 | public void onServiceConnected(ComponentName className, 100 | IBinder service) { 101 | // We've bound to SignalRService, cast the IBinder and get SignalRService instance 102 | SignalRService.LocalBinder binder = (SignalRService.LocalBinder) service; 103 | mService = binder.getService(); 104 | mBound = true; 105 | } 106 | 107 | @Override 108 | public void onServiceDisconnected(ComponentName arg0) { 109 | mBound = false; 110 | } 111 | }; 112 | } 113 | -------------------------------------------------------------------------------- /Src/SignalR Android/app/src/main/java/com/example/simplesignalrclient/SignalRService.java: -------------------------------------------------------------------------------- 1 | package com.example.simplesignalrclient; 2 | 3 | import android.app.Service; 4 | import android.content.Intent; 5 | import android.os.Binder; 6 | import android.os.Handler; 7 | import android.os.IBinder; 8 | import android.os.Looper; 9 | import android.util.Log; 10 | import android.widget.Toast; 11 | 12 | import java.util.concurrent.ExecutionException; 13 | 14 | 15 | import microsoft.aspnet.signalr.client.Platform; 16 | import microsoft.aspnet.signalr.client.SignalRFuture; 17 | import microsoft.aspnet.signalr.client.http.android.AndroidPlatformComponent; 18 | import microsoft.aspnet.signalr.client.hubs.HubConnection; 19 | import microsoft.aspnet.signalr.client.hubs.HubProxy; 20 | import microsoft.aspnet.signalr.client.hubs.SubscriptionHandler2; 21 | import microsoft.aspnet.signalr.client.transport.ClientTransport; 22 | import microsoft.aspnet.signalr.client.transport.ServerSentEventsTransport; 23 | 24 | public class SignalRService extends Service { 25 | private HubConnection mHubConnection; 26 | private HubProxy mHubProxy; 27 | private Handler mHandler; // to display Toast message 28 | private final IBinder mBinder = new LocalBinder(); // Binder given to clients 29 | 30 | public SignalRService() { 31 | } 32 | 33 | @Override 34 | public void onCreate() { 35 | super.onCreate(); 36 | mHandler = new Handler(Looper.getMainLooper()); 37 | } 38 | 39 | @Override 40 | public int onStartCommand(Intent intent, int flags, int startId) { 41 | int result = super.onStartCommand(intent, flags, startId); 42 | startSignalR(); 43 | return result; 44 | } 45 | 46 | @Override 47 | public void onDestroy() { 48 | mHubConnection.stop(); 49 | super.onDestroy(); 50 | } 51 | 52 | @Override 53 | public IBinder onBind(Intent intent) { 54 | // Return the communication channel to the service. 55 | startSignalR(); 56 | return mBinder; 57 | } 58 | 59 | /** 60 | * Class used for the client Binder. Because we know this service always 61 | * runs in the same process as its clients, we don't need to deal with IPC. 62 | */ 63 | public class LocalBinder extends Binder { 64 | public SignalRService getService() { 65 | // Return this instance of SignalRService so clients can call public methods 66 | return SignalRService.this; 67 | } 68 | } 69 | 70 | /** 71 | * method for clients (activities) 72 | */ 73 | public void sendMessage(String message) { 74 | String SERVER_METHOD_SEND = "send"; 75 | mHubProxy.invoke(SERVER_METHOD_SEND, message); 76 | } 77 | 78 | /** 79 | * method for clients (activities) 80 | */ 81 | public void sendMessage_To(String receiverName, String message) { 82 | String SERVER_METHOD_SEND_TO = "send"; 83 | mHubProxy.invoke(SERVER_METHOD_SEND_TO, receiverName, message); 84 | } 85 | 86 | private void startSignalR() { 87 | Platform.loadPlatformComponent(new AndroidPlatformComponent()); 88 | 89 | String serverUrl = "http://192.168.0.196:8099"; 90 | mHubConnection = new HubConnection(serverUrl); 91 | String SERVER_HUB_CHAT = "ChatHub"; 92 | mHubProxy = mHubConnection.createHubProxy(SERVER_HUB_CHAT); 93 | 94 | ClientTransport clientTransport = new ServerSentEventsTransport(mHubConnection.getLogger()); 95 | SignalRFuture signalRFuture = mHubConnection.start(clientTransport); 96 | 97 | try { 98 | signalRFuture.get(); 99 | } catch (InterruptedException | ExecutionException e) { 100 | Log.e("SimpleSignalR", e.toString()); 101 | return; 102 | } 103 | 104 | sendMessage("Hello from BNK!"); 105 | 106 | 107 | String CLIENT_METHOD_BROADAST_MESSAGE = "broadcastMessage"; 108 | mHubProxy.on(CLIENT_METHOD_BROADAST_MESSAGE, 109 | new SubscriptionHandler2() { 110 | @Override 111 | public void run(final String name,final String msg) { 112 | final String finalMsg = msg.toString(); 113 | // display Toast message 114 | mHandler.post(new Runnable() { 115 | @Override 116 | public void run() { 117 | Toast.makeText(getApplicationContext(), finalMsg, Toast.LENGTH_SHORT).show(); 118 | } 119 | }); 120 | } 121 | } 122 | , String.class,String.class); 123 | 124 | 125 | // Subscribe to the received event 126 | /* mHubConnection.received(new MessageReceivedHandler() { 127 | 128 | @Override 129 | public void onMessageReceived(final JsonElement json) { 130 | Log.e("onMessageReceived ", json.toString()); 131 | mHandler.post(new Runnable() { 132 | @Override 133 | public void run() { 134 | Toast.makeText(getApplicationContext(), json.toString(), Toast.LENGTH_SHORT).show(); 135 | } 136 | }); 137 | } 138 | });*/ 139 | 140 | } 141 | 142 | } 143 | -------------------------------------------------------------------------------- /Src/SignalR Android/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 18 | 23 | 24 | 25 |