├── NettyAndroid
├── .gradle
│ ├── 4.6
│ │ ├── fileChanges
│ │ │ └── last-build.bin
│ │ ├── fileContent
│ │ │ ├── annotation-processors.bin
│ │ │ └── fileContent.lock
│ │ ├── fileHashes
│ │ │ ├── fileHashes.bin
│ │ │ ├── fileHashes.lock
│ │ │ └── resourceHashesCache.bin
│ │ ├── javaCompile
│ │ │ ├── classAnalysis.bin
│ │ │ ├── jarAnalysis.bin
│ │ │ ├── javaCompile.lock
│ │ │ ├── taskHistory.bin
│ │ │ └── taskJars.bin
│ │ └── taskHistory
│ │ │ ├── taskHistory.bin
│ │ │ └── taskHistory.lock
│ ├── buildOutputCleanup
│ │ ├── buildOutputCleanup.lock
│ │ ├── cache.properties
│ │ └── outputFiles.bin
│ └── vcsWorkingDirs
│ │ └── gc.properties
├── .idea
│ ├── caches
│ │ └── build_file_checksums.ser
│ ├── codeStyles
│ │ └── Project.xml
│ ├── gradle.xml
│ ├── libraries
│ │ ├── Gradle____local_aars____home_lucher_git_NettyAndroid_app_libs_javassist_3_24_1_jar_unspecified_jar.xml
│ │ ├── Gradle____local_aars____home_lucher_git_NettyAndroid_app_libs_msgpack_0_6_12_jar_unspecified_jar.xml
│ │ ├── Gradle____local_aars____home_lucher_git_NettyAndroid_app_libs_netty_all_4_1_15_Final_jar_unspecified_jar.xml
│ │ ├── Gradle__android_arch_core_common_1_1_1_jar.xml
│ │ ├── Gradle__android_arch_core_runtime_1_1_1.xml
│ │ ├── Gradle__android_arch_lifecycle_common_1_1_1_jar.xml
│ │ ├── Gradle__android_arch_lifecycle_livedata_1_1_1.xml
│ │ ├── Gradle__android_arch_lifecycle_livedata_core_1_1_1.xml
│ │ ├── Gradle__android_arch_lifecycle_runtime_1_1_1.xml
│ │ ├── Gradle__android_arch_lifecycle_viewmodel_1_1_1.xml
│ │ ├── Gradle__com_android_support_animated_vector_drawable_28_0_0.xml
│ │ ├── Gradle__com_android_support_appcompat_v7_28_0_0.xml
│ │ ├── Gradle__com_android_support_asynclayoutinflater_28_0_0.xml
│ │ ├── Gradle__com_android_support_collections_28_0_0_jar.xml
│ │ ├── Gradle__com_android_support_constraint_constraint_layout_1_1_3.xml
│ │ ├── Gradle__com_android_support_constraint_constraint_layout_solver_1_1_3_jar.xml
│ │ ├── Gradle__com_android_support_coordinatorlayout_28_0_0.xml
│ │ ├── Gradle__com_android_support_cursoradapter_28_0_0.xml
│ │ ├── Gradle__com_android_support_customview_28_0_0.xml
│ │ ├── Gradle__com_android_support_documentfile_28_0_0.xml
│ │ ├── Gradle__com_android_support_drawerlayout_28_0_0.xml
│ │ ├── Gradle__com_android_support_interpolator_28_0_0.xml
│ │ ├── Gradle__com_android_support_loader_28_0_0.xml
│ │ ├── Gradle__com_android_support_localbroadcastmanager_28_0_0.xml
│ │ ├── Gradle__com_android_support_print_28_0_0.xml
│ │ ├── Gradle__com_android_support_slidingpanelayout_28_0_0.xml
│ │ ├── Gradle__com_android_support_support_annotations_28_0_0_jar.xml
│ │ ├── Gradle__com_android_support_support_compat_28_0_0.xml
│ │ ├── Gradle__com_android_support_support_core_ui_28_0_0.xml
│ │ ├── Gradle__com_android_support_support_core_utils_28_0_0.xml
│ │ ├── Gradle__com_android_support_support_fragment_28_0_0.xml
│ │ ├── Gradle__com_android_support_support_vector_drawable_28_0_0.xml
│ │ ├── Gradle__com_android_support_swiperefreshlayout_28_0_0.xml
│ │ ├── Gradle__com_android_support_test_espresso_espresso_core_3_0_2.xml
│ │ ├── Gradle__com_android_support_test_espresso_espresso_idling_resource_3_0_2.xml
│ │ ├── Gradle__com_android_support_test_monitor_1_0_2.xml
│ │ ├── Gradle__com_android_support_test_runner_1_0_2.xml
│ │ ├── Gradle__com_android_support_versionedparcelable_28_0_0.xml
│ │ ├── Gradle__com_android_support_viewpager_28_0_0.xml
│ │ ├── Gradle__com_google_code_findbugs_jsr305_2_0_1_jar.xml
│ │ ├── Gradle__com_jakewharton_butterknife_8_4_0.xml
│ │ ├── Gradle__com_jakewharton_butterknife_annotations_8_4_0_jar.xml
│ │ ├── Gradle__com_squareup_javawriter_2_1_1_jar.xml
│ │ ├── Gradle__javax_inject_javax_inject_1_jar.xml
│ │ ├── Gradle__junit_junit_4_12_jar.xml
│ │ ├── Gradle__net_sf_kxml_kxml2_2_3_0_jar.xml
│ │ ├── Gradle__org_greenrobot_eventbus_3_1_1_jar.xml
│ │ ├── Gradle__org_hamcrest_hamcrest_core_1_3_jar.xml
│ │ ├── Gradle__org_hamcrest_hamcrest_integration_1_3_jar.xml
│ │ └── Gradle__org_hamcrest_hamcrest_library_1_3_jar.xml
│ ├── markdown-navigator
│ │ └── profiles_settings.xml
│ ├── misc.xml
│ ├── modules.xml
│ ├── runConfigurations.xml
│ └── workspace.xml
├── NettyAndroid.iml
├── app
│ ├── .gitignore
│ ├── app.iml
│ ├── build.gradle
│ ├── libs
│ │ ├── javassist-3.24.1.jar
│ │ ├── msgpack-0.6.12.jar
│ │ └── netty-all-4.1.15.Final.jar
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── netty
│ │ │ └── android
│ │ │ └── ExampleInstrumentedTest.java
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── netty
│ │ │ │ └── android
│ │ │ │ ├── MainActivity.java
│ │ │ │ ├── client
│ │ │ │ ├── NettyClient.java
│ │ │ │ └── NettyClientHandler.java
│ │ │ │ ├── coder
│ │ │ │ ├── MessageConverter.java
│ │ │ │ ├── MessagePackDecoder.java
│ │ │ │ └── MessagePackEncoder.java
│ │ │ │ ├── event
│ │ │ │ ├── BaseEvent.java
│ │ │ │ ├── EventType.java
│ │ │ │ └── TestEvent.java
│ │ │ │ └── util
│ │ │ │ └── TimeUtil.java
│ │ └── res
│ │ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ │ ├── drawable
│ │ │ └── ic_launcher_background.xml
│ │ │ ├── layout
│ │ │ └── activity_main.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ └── values
│ │ │ ├── colors.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── netty
│ │ └── android
│ │ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── local.properties
└── settings.gradle
├── NettyCSharp
├── App.config
├── App.xaml
├── App.xaml.cs
├── MainWindow.xaml
├── MainWindow.xaml.cs
├── NettyCSharp.csproj
├── NettyCSharp.csproj.user
├── NettyCSharp.sln
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── com.netty.csharp
│ ├── client
│ │ ├── NettyClient.cs
│ │ └── NettyClientHandler.cs
│ ├── coder
│ │ ├── MessagePackDecoder.cs
│ │ └── MessagePackEncoder.cs
│ └── event
│ │ ├── BaseEvent.cs
│ │ ├── EventType.cs
│ │ └── TestEvent.cs
└── packages.config
├── NettyServer
├── .classpath
├── .project
├── .settings
│ └── org.eclipse.jdt.core.prefs
├── libs
│ ├── fastjson-1.1.31.jar
│ ├── guava-23.0.jar
│ ├── javassist-3.24.1.jar
│ ├── msgpack-0.6.12.jar
│ └── netty-all-4.1.15.Final.jar
├── src
│ └── com
│ │ └── netty
│ │ └── test
│ │ ├── RunClient.java
│ │ ├── RunServer.java
│ │ ├── Test.java
│ │ ├── client
│ │ ├── NettyClient.java
│ │ └── NettyClientHandler.java
│ │ ├── coder
│ │ ├── MessageConverter.java
│ │ ├── MessagePackDecoder.java
│ │ └── MessagePackEncoder.java
│ │ ├── event
│ │ ├── BaseEvent.java
│ │ ├── EventType.java
│ │ └── TestEvent.java
│ │ ├── eventbus
│ │ ├── EventBusFactory.java
│ │ └── IEventListener.java
│ │ ├── server
│ │ ├── ChannelWraper.java
│ │ ├── NettyServer.java
│ │ ├── ProtocolDecoder.java
│ │ └── ServerChannelHandler.java
│ │ └── util
│ │ └── TimeUtil.java
└── web
│ └── index.html
├── README.md
└── 效果图
├── 20190307-214118.gif
├── 20190307-214118.mp4
├── Android Client.png
├── CShart Client.png
├── Java Client.png
├── Java Server.png
└── WebSocket Client.png
/NettyAndroid/.gradle/4.6/fileChanges/last-build.bin:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/NettyAndroid/.gradle/4.6/fileContent/annotation-processors.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lucher/MultiPlatformNettyDemo/69d6efc8e46f4289491037304397d3ef26f86916/NettyAndroid/.gradle/4.6/fileContent/annotation-processors.bin
--------------------------------------------------------------------------------
/NettyAndroid/.gradle/4.6/fileContent/fileContent.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lucher/MultiPlatformNettyDemo/69d6efc8e46f4289491037304397d3ef26f86916/NettyAndroid/.gradle/4.6/fileContent/fileContent.lock
--------------------------------------------------------------------------------
/NettyAndroid/.gradle/4.6/fileHashes/fileHashes.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lucher/MultiPlatformNettyDemo/69d6efc8e46f4289491037304397d3ef26f86916/NettyAndroid/.gradle/4.6/fileHashes/fileHashes.bin
--------------------------------------------------------------------------------
/NettyAndroid/.gradle/4.6/fileHashes/fileHashes.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lucher/MultiPlatformNettyDemo/69d6efc8e46f4289491037304397d3ef26f86916/NettyAndroid/.gradle/4.6/fileHashes/fileHashes.lock
--------------------------------------------------------------------------------
/NettyAndroid/.gradle/4.6/fileHashes/resourceHashesCache.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lucher/MultiPlatformNettyDemo/69d6efc8e46f4289491037304397d3ef26f86916/NettyAndroid/.gradle/4.6/fileHashes/resourceHashesCache.bin
--------------------------------------------------------------------------------
/NettyAndroid/.gradle/4.6/javaCompile/classAnalysis.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lucher/MultiPlatformNettyDemo/69d6efc8e46f4289491037304397d3ef26f86916/NettyAndroid/.gradle/4.6/javaCompile/classAnalysis.bin
--------------------------------------------------------------------------------
/NettyAndroid/.gradle/4.6/javaCompile/jarAnalysis.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lucher/MultiPlatformNettyDemo/69d6efc8e46f4289491037304397d3ef26f86916/NettyAndroid/.gradle/4.6/javaCompile/jarAnalysis.bin
--------------------------------------------------------------------------------
/NettyAndroid/.gradle/4.6/javaCompile/javaCompile.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lucher/MultiPlatformNettyDemo/69d6efc8e46f4289491037304397d3ef26f86916/NettyAndroid/.gradle/4.6/javaCompile/javaCompile.lock
--------------------------------------------------------------------------------
/NettyAndroid/.gradle/4.6/javaCompile/taskHistory.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lucher/MultiPlatformNettyDemo/69d6efc8e46f4289491037304397d3ef26f86916/NettyAndroid/.gradle/4.6/javaCompile/taskHistory.bin
--------------------------------------------------------------------------------
/NettyAndroid/.gradle/4.6/javaCompile/taskJars.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lucher/MultiPlatformNettyDemo/69d6efc8e46f4289491037304397d3ef26f86916/NettyAndroid/.gradle/4.6/javaCompile/taskJars.bin
--------------------------------------------------------------------------------
/NettyAndroid/.gradle/4.6/taskHistory/taskHistory.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lucher/MultiPlatformNettyDemo/69d6efc8e46f4289491037304397d3ef26f86916/NettyAndroid/.gradle/4.6/taskHistory/taskHistory.bin
--------------------------------------------------------------------------------
/NettyAndroid/.gradle/4.6/taskHistory/taskHistory.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lucher/MultiPlatformNettyDemo/69d6efc8e46f4289491037304397d3ef26f86916/NettyAndroid/.gradle/4.6/taskHistory/taskHistory.lock
--------------------------------------------------------------------------------
/NettyAndroid/.gradle/buildOutputCleanup/buildOutputCleanup.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lucher/MultiPlatformNettyDemo/69d6efc8e46f4289491037304397d3ef26f86916/NettyAndroid/.gradle/buildOutputCleanup/buildOutputCleanup.lock
--------------------------------------------------------------------------------
/NettyAndroid/.gradle/buildOutputCleanup/cache.properties:
--------------------------------------------------------------------------------
1 | #Wed Feb 27 14:23:08 CST 2019
2 | gradle.version=4.6
3 |
--------------------------------------------------------------------------------
/NettyAndroid/.gradle/buildOutputCleanup/outputFiles.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lucher/MultiPlatformNettyDemo/69d6efc8e46f4289491037304397d3ef26f86916/NettyAndroid/.gradle/buildOutputCleanup/outputFiles.bin
--------------------------------------------------------------------------------
/NettyAndroid/.gradle/vcsWorkingDirs/gc.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lucher/MultiPlatformNettyDemo/69d6efc8e46f4289491037304397d3ef26f86916/NettyAndroid/.gradle/vcsWorkingDirs/gc.properties
--------------------------------------------------------------------------------
/NettyAndroid/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lucher/MultiPlatformNettyDemo/69d6efc8e46f4289491037304397d3ef26f86916/NettyAndroid/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/NettyAndroid/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle____local_aars____home_lucher_git_NettyAndroid_app_libs_javassist_3_24_1_jar_unspecified_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle____local_aars____home_lucher_git_NettyAndroid_app_libs_msgpack_0_6_12_jar_unspecified_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle____local_aars____home_lucher_git_NettyAndroid_app_libs_netty_all_4_1_15_Final_jar_unspecified_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__android_arch_core_common_1_1_1_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__android_arch_core_runtime_1_1_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__android_arch_lifecycle_common_1_1_1_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__android_arch_lifecycle_livedata_1_1_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__android_arch_lifecycle_livedata_core_1_1_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__android_arch_lifecycle_runtime_1_1_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__android_arch_lifecycle_viewmodel_1_1_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_animated_vector_drawable_28_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_appcompat_v7_28_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_asynclayoutinflater_28_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_collections_28_0_0_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_constraint_constraint_layout_1_1_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_constraint_constraint_layout_solver_1_1_3_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_coordinatorlayout_28_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_cursoradapter_28_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_customview_28_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_documentfile_28_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_drawerlayout_28_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_interpolator_28_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_loader_28_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_localbroadcastmanager_28_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_print_28_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_slidingpanelayout_28_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_support_annotations_28_0_0_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_support_compat_28_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_support_core_ui_28_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_support_core_utils_28_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_support_fragment_28_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_support_vector_drawable_28_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_swiperefreshlayout_28_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_test_espresso_espresso_core_3_0_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_test_espresso_espresso_idling_resource_3_0_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_test_monitor_1_0_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_test_runner_1_0_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_versionedparcelable_28_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_android_support_viewpager_28_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_google_code_findbugs_jsr305_2_0_1_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_jakewharton_butterknife_8_4_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_jakewharton_butterknife_annotations_8_4_0_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__com_squareup_javawriter_2_1_1_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__javax_inject_javax_inject_1_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__junit_junit_4_12_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__net_sf_kxml_kxml2_2_3_0_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__org_greenrobot_eventbus_3_1_1_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__org_hamcrest_hamcrest_integration_1_3_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/libraries/Gradle__org_hamcrest_hamcrest_library_1_3_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/markdown-navigator/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
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 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/NettyAndroid/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/NettyAndroid/NettyAndroid.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/NettyAndroid/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/NettyAndroid/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | generateDebugSources
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
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 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
--------------------------------------------------------------------------------
/NettyAndroid/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "com.netty.android"
7 | minSdkVersion 14
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(include: ['*.jar'], dir: 'libs')
23 | implementation 'com.android.support:appcompat-v7:28.0.0'
24 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
25 | testImplementation 'junit:junit:4.12'
26 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
28 | //butterknife
29 | implementation 'com.jakewharton:butterknife:8.4.0'
30 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
31 | //eventbus
32 | implementation 'org.greenrobot:eventbus:3.1.1'
33 | }
34 |
--------------------------------------------------------------------------------
/NettyAndroid/app/libs/javassist-3.24.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lucher/MultiPlatformNettyDemo/69d6efc8e46f4289491037304397d3ef26f86916/NettyAndroid/app/libs/javassist-3.24.1.jar
--------------------------------------------------------------------------------
/NettyAndroid/app/libs/msgpack-0.6.12.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lucher/MultiPlatformNettyDemo/69d6efc8e46f4289491037304397d3ef26f86916/NettyAndroid/app/libs/msgpack-0.6.12.jar
--------------------------------------------------------------------------------
/NettyAndroid/app/libs/netty-all-4.1.15.Final.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lucher/MultiPlatformNettyDemo/69d6efc8e46f4289491037304397d3ef26f86916/NettyAndroid/app/libs/netty-all-4.1.15.Final.jar
--------------------------------------------------------------------------------
/NettyAndroid/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/NettyAndroid/app/src/androidTest/java/com/netty/android/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.netty.android;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.netty.android", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/NettyAndroid/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
14 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/NettyAndroid/app/src/main/java/com/netty/android/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.netty.android;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.text.method.ScrollingMovementMethod;
6 | import android.widget.EditText;
7 | import android.widget.TextView;
8 |
9 | import com.netty.android.client.NettyClient;
10 | import com.netty.android.event.EventType;
11 | import com.netty.android.event.TestEvent;
12 |
13 | import org.greenrobot.eventbus.EventBus;
14 | import org.greenrobot.eventbus.Subscribe;
15 | import org.greenrobot.eventbus.ThreadMode;
16 |
17 | import butterknife.BindView;
18 | import butterknife.ButterKnife;
19 | import butterknife.OnClick;
20 |
21 | /**
22 | * Netty示例安卓端主界面
23 | *
24 | * @author lucher
25 | */
26 | public class MainActivity extends AppCompatActivity {
27 |
28 | // Server端IP地址,根据实际情况进行修改
29 | static final String HOST = System.getProperty("host", "192.168.1.111");
30 | // Netty服务端监听端口号
31 | static final int PORT = Integer.parseInt(System.getProperty("port", "8888"));
32 |
33 | //发送内容编辑框
34 | @BindView(R.id.editText)
35 | EditText editText;
36 | //内容显示区域
37 | @BindView(R.id.textView)
38 | TextView textView;
39 |
40 | //Netty 客户端
41 | private NettyClient mClient;
42 |
43 | @Override
44 | protected void onCreate(Bundle savedInstanceState) {
45 | super.onCreate(savedInstanceState);
46 | setContentView(R.layout.activity_main);
47 | ButterKnife.bind(this);
48 |
49 | //连接服务器端
50 | mClient = new NettyClient(HOST, PORT);
51 | mClient.start();
52 | //让内容区可以滚动
53 | textView.setMovementMethod(ScrollingMovementMethod.getInstance());
54 | }
55 |
56 | /**
57 | * 开始按钮点击
58 | */
59 | @OnClick(R.id.btnSend)
60 | public void onSendClick() {
61 | try {
62 | // 发送测试消息
63 | mClient.sendMessage(new TestEvent(EventType.TEST_EVENT, "Android", editText.getText().toString()));
64 | } catch (Exception e) {
65 | e.printStackTrace();
66 | }
67 | }
68 |
69 | /**
70 | * EventBus事件处理
71 | *
72 | * @param msg
73 | */
74 | @Subscribe(threadMode = ThreadMode.MAIN)
75 | public void onMessageEvent(String msg) {
76 | textView.setText(msg + "\n" + textView.getText().toString());
77 | }
78 |
79 | //EventBus注册
80 | @Override
81 | public void onStart() {
82 | super.onStart();
83 | EventBus.getDefault().register(this);
84 | }
85 |
86 | //取消EventBus注册
87 | @Override
88 | public void onStop() {
89 | super.onStop();
90 | EventBus.getDefault().unregister(this);
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/NettyAndroid/app/src/main/java/com/netty/android/client/NettyClient.java:
--------------------------------------------------------------------------------
1 | package com.netty.android.client;
2 |
3 | import com.netty.android.coder.MessagePackDecoder;
4 | import com.netty.android.coder.MessagePackEncoder;
5 | import com.netty.android.event.BaseEvent;
6 |
7 | import org.greenrobot.eventbus.EventBus;
8 |
9 | import io.netty.bootstrap.Bootstrap;
10 | import io.netty.channel.Channel;
11 | import io.netty.channel.ChannelFuture;
12 | import io.netty.channel.ChannelInitializer;
13 | import io.netty.channel.ChannelOption;
14 | import io.netty.channel.ChannelPipeline;
15 | import io.netty.channel.EventLoopGroup;
16 | import io.netty.channel.nio.NioEventLoopGroup;
17 | import io.netty.channel.socket.SocketChannel;
18 | import io.netty.channel.socket.nio.NioSocketChannel;
19 | import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
20 | import io.netty.handler.codec.LengthFieldPrepender;
21 |
22 | /**
23 | * Netty Java客户端
24 | *
25 | * @author lucher
26 | */
27 | public class NettyClient extends Thread {
28 |
29 | // Server端IP地址
30 | private String host;
31 | // Netty服务端监听端口号
32 | private int port;
33 | // 通信管道
34 | private Channel channel;
35 |
36 | public NettyClient(String host, int port) {
37 | this.host = host;
38 | this.port = port;
39 | }
40 |
41 | @Override
42 | public void run() {
43 | try {
44 | startClient();
45 | } catch (Exception e) {
46 | e.printStackTrace();
47 | }
48 | }
49 |
50 | /**
51 | * 发送消息
52 | *
53 | * @param event
54 | */
55 | public void sendMessage(BaseEvent event) {
56 | if (channel != null && channel.isActive()) {//已建立连接状态
57 | channel.writeAndFlush(event);
58 | } else {
59 | EventBus.getDefault().post("还未建立连接,不能发送消息");
60 | }
61 | }
62 |
63 | /**
64 | * 开启客户端
65 | *
66 | * @throws Exception
67 | */
68 | private void startClient() throws Exception {
69 | EventLoopGroup group = new NioEventLoopGroup();
70 | try {
71 | //NIO客户端启动辅助类,降低客户端开发复杂度
72 | Bootstrap bootstrap = new Bootstrap();
73 | bootstrap.group(group)
74 | // 当执行channelfactory的newChannel方法时,会创建NioSocketChannel实例
75 | .channel(NioSocketChannel.class)
76 | // ChannelOption.TCP_NODELAY参数对应于套接字选项中的TCP_NODELAY,该参数的使用与Nagle算法有关
77 | // Nagle算法是将小的数据包组装为更大的帧然后进行发送,而不是输入一次发送一次,因此在数据包不足的时候会等待其他数据的到了,组装成大的数据包进行发送,虽然该方式有效提高网络的有效
78 | // 负载,但是却造成了延时,而该参数的作用就是禁止使用Nagle算法,使用于小数据即时传输,于TCP_NODELAY相对应的是TCP_CORK,该选项是需要等到发送的数据量最大的时候,一次性发送
79 | // 数据,适用于文件传输。
80 | .option(ChannelOption.TCP_NODELAY, true)
81 | // handler()和childHandler()的主要区别是,handler()是发生在初始化的时候,childHandler()是发生在客户端连接之后
82 | .handler(new ChannelInitializer() {
83 | @Override
84 | protected void initChannel(SocketChannel ch) throws Exception {
85 | ChannelPipeline pipeline = ch.pipeline();
86 | // Tcp粘包处理,添加一个LengthFieldBasedFrameDecoder解码器,它会在解码时按照消息头的长度来进行解码。
87 | pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(65535, 0, 4, 0, 4));
88 | // MessagePack解码器,消息进来后先由frameDecoder处理,再给msgPackDecoder处理
89 | pipeline.addLast("msgPackDecoder", new MessagePackDecoder());
90 | // Tcp粘包处理,添加一个
91 | // LengthFieldPrepender编码器,它会在ByteBuf之前增加4个字节的字段,用于记录消息长度。
92 | pipeline.addLast("frameEncoder", new LengthFieldPrepender(4));
93 | // MessagePack编码器,消息发出之前先由frameEncoder处理,再给msgPackEncoder处理
94 | pipeline.addLast("msgPackEncoder", new MessagePackEncoder());
95 | // 消息处理handler
96 | pipeline.addLast("handler", new NettyClientHandler());
97 | }
98 | });
99 | // 发起异步连接操作
100 | ChannelFuture f = bootstrap.connect(host, port).sync();
101 | channel = f.channel();
102 | System.out.println("客户端已启动");
103 | // 等待客户端链路关闭
104 | f.channel().closeFuture().sync();
105 | } catch (Exception e) {
106 | e.printStackTrace();
107 | System.out.println("连接失败,服务端是否开启?");
108 | } finally {
109 | // 优雅退出,释放NIO线程组
110 | group.shutdownGracefully();
111 | }
112 | }
113 | }
--------------------------------------------------------------------------------
/NettyAndroid/app/src/main/java/com/netty/android/client/NettyClientHandler.java:
--------------------------------------------------------------------------------
1 | package com.netty.android.client;
2 |
3 | import com.netty.android.coder.MessageConverter;
4 | import com.netty.android.event.EventType;
5 | import com.netty.android.event.TestEvent;
6 |
7 | import org.greenrobot.eventbus.EventBus;
8 | import org.msgpack.type.ArrayValue;
9 | import org.msgpack.type.IntegerValue;
10 |
11 | import io.netty.channel.ChannelHandlerContext;
12 | import io.netty.channel.SimpleChannelInboundHandler;
13 |
14 | /**
15 | * 处理客户端的channel
16 | *
17 | * @author lucher
18 | */
19 | public class NettyClientHandler extends SimpleChannelInboundHandler {
20 |
21 | @Override
22 | protected void channelRead0(ChannelHandlerContext arg0, ArrayValue value) throws Exception {
23 | // 获取EventType,BaseEvent的第一个字段是EventType,这是约定好的
24 | int typeIndex = ((IntegerValue) value.get(0)).intValue();
25 | EventType eventType = EventType.class.getEnumConstants()[typeIndex];
26 | switch (eventType) {
27 | case TEST_EVENT:
28 | TestEvent testEvent = MessageConverter.converter(value, TestEvent.class);
29 | System.out.println("Client接收到消息:" + testEvent);
30 | EventBus.getDefault().post(testEvent.toString());
31 |
32 | break;
33 | case OTHER_EVENT:
34 | System.out.println("Client接收到消息:其他事件,暂未处理");
35 |
36 | break;
37 | default:
38 | break;
39 | }
40 | }
41 |
42 | @Override
43 | public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
44 | super.channelReadComplete(ctx);
45 | ctx.flush();
46 | }
47 |
48 | @Override
49 | public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
50 | super.channelRegistered(ctx);
51 | System.out.println("Client channelRegistered:" + ctx);
52 | }
53 |
54 | @Override
55 | public void channelActive(ChannelHandlerContext ctx) throws Exception {
56 | System.out.println("Client channelActive:" + ctx);
57 | EventBus.getDefault().post("建立连接:" + ctx);
58 | }
59 |
60 | @Override
61 | public void channelInactive(ChannelHandlerContext ctx) throws Exception {
62 | super.channelInactive(ctx);
63 | System.out.println("Client channelInactive:" + ctx);
64 | EventBus.getDefault().post("连接断开:" + ctx);
65 | }
66 |
67 | @Override
68 | public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {// 断开链接事件
69 | super.channelUnregistered(ctx);
70 | System.out.println("Client channelUnregistered:" + ctx);
71 | }
72 |
73 | @Override
74 | public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
75 | System.out.println("Client exception:" + cause.getMessage());
76 | EventBus.getDefault().post("Client exception:" + cause.getMessage());
77 | }
78 |
79 | }
--------------------------------------------------------------------------------
/NettyAndroid/app/src/main/java/com/netty/android/coder/MessageConverter.java:
--------------------------------------------------------------------------------
1 | package com.netty.android.coder;
2 |
3 | import org.msgpack.MessagePack;
4 | import org.msgpack.type.Value;
5 | import org.msgpack.unpacker.Converter;
6 |
7 | import java.io.IOException;
8 |
9 | import io.netty.handler.codec.http.FullHttpRequest;
10 | import io.netty.handler.codec.http.websocketx.WebSocketFrame;
11 |
12 | /**
13 | * message 转换类
14 | *
15 | * @author lucher
16 | *
17 | */
18 | public class MessageConverter {
19 |
20 | /**
21 | * 将value转为指定的实体类
22 | *
23 | * @param value
24 | * @param cls
25 | * @return
26 | * @throws IOException
27 | */
28 | public static T converter(Value value, Class cls) throws IOException {
29 | Converter converter = new Converter(new MessagePack(), value);
30 | T obj = null;
31 | try {
32 | obj = converter.read(cls);
33 | } finally {
34 | converter.close();// 关闭coverter
35 | converter = null;
36 | }FullHttpRequest a;WebSocketFrame b;
37 | return obj;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/NettyAndroid/app/src/main/java/com/netty/android/coder/MessagePackDecoder.java:
--------------------------------------------------------------------------------
1 | package com.netty.android.coder;
2 |
3 |
4 | import org.msgpack.MessagePack;
5 |
6 | import java.util.List;
7 |
8 | import io.netty.buffer.ByteBuf;
9 | import io.netty.channel.ChannelHandlerContext;
10 | import io.netty.handler.codec.MessageToMessageDecoder;
11 |
12 | /**
13 | * MessagePack实现的消息解码器
14 | *
15 | * @author lucher
16 | *
17 | */
18 | public class MessagePackDecoder extends MessageToMessageDecoder {
19 |
20 | @Override
21 | protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List