├── .gitattributes
├── .gitignore
├── Android
├── Blink
│ ├── .gitignore
│ ├── build.gradle
│ ├── gradle.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── library
│ │ ├── .gitignore
│ │ ├── build.gradle
│ │ ├── proguard-rules.pro
│ │ └── src
│ │ │ ├── androidTest
│ │ │ └── java
│ │ │ │ └── net
│ │ │ │ └── qiujuer
│ │ │ │ └── blink
│ │ │ │ └── ApplicationTest.java
│ │ │ └── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── java
│ │ │ └── net
│ │ │ │ └── qiujuer
│ │ │ │ └── blink
│ │ │ │ ├── Blink.java
│ │ │ │ ├── async
│ │ │ │ ├── AsyncEventArgs.java
│ │ │ │ ├── AsyncReceiveDispatcher.java
│ │ │ │ ├── AsyncSendDispatcher.java
│ │ │ │ ├── AsyncSocketAdapter.java
│ │ │ │ └── HandleSelector.java
│ │ │ │ ├── box
│ │ │ │ ├── BaseReceivePacket.java
│ │ │ │ ├── BaseSendPacket.java
│ │ │ │ ├── ByteReceivePacket.java
│ │ │ │ ├── ByteSendPacket.java
│ │ │ │ ├── FileReceivePacket.java
│ │ │ │ ├── FileSendPacket.java
│ │ │ │ ├── StringReceivePacket.java
│ │ │ │ └── StringSendPacket.java
│ │ │ │ ├── core
│ │ │ │ ├── BlinkConn.java
│ │ │ │ ├── BlinkDelivery.java
│ │ │ │ ├── BlinkPacket.java
│ │ │ │ ├── BlinkParser.java
│ │ │ │ ├── Packet.java
│ │ │ │ ├── ReceiveDelivery.java
│ │ │ │ ├── ReceivePacket.java
│ │ │ │ ├── Receiver.java
│ │ │ │ ├── Resource.java
│ │ │ │ ├── SendDelivery.java
│ │ │ │ ├── SendPacket.java
│ │ │ │ └── Sender.java
│ │ │ │ ├── kit
│ │ │ │ ├── BitConverter.java
│ │ │ │ ├── BlinkLog.java
│ │ │ │ ├── BlinkParserImpl.java
│ │ │ │ ├── DiskResource.java
│ │ │ │ ├── Disposable.java
│ │ │ │ ├── ExecutorDelivery.java
│ │ │ │ └── HashConverter.java
│ │ │ │ └── listener
│ │ │ │ ├── BlinkListener.java
│ │ │ │ ├── ReceiveListener.java
│ │ │ │ └── SendListener.java
│ │ │ └── res
│ │ │ └── values
│ │ │ └── strings.xml
│ ├── old
│ │ ├── .gitignore
│ │ ├── build.gradle
│ │ ├── proguard-rules.pro
│ │ └── src
│ │ │ ├── androidTest
│ │ │ └── java
│ │ │ │ └── net
│ │ │ │ └── qiujuer
│ │ │ │ └── blink
│ │ │ │ └── ApplicationTest.java
│ │ │ └── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── java
│ │ │ └── net
│ │ │ │ └── qiujuer
│ │ │ │ └── blink
│ │ │ │ ├── Blink.java
│ │ │ │ ├── BlinkLog.java
│ │ │ │ ├── DiskResource.java
│ │ │ │ ├── ExecutorDelivery.java
│ │ │ │ ├── SocketAdapter.java
│ │ │ │ ├── box
│ │ │ │ ├── ByteReceivePacket.java
│ │ │ │ ├── ByteSendPacket.java
│ │ │ │ ├── FileReceivePacket.java
│ │ │ │ ├── FileSendPacket.java
│ │ │ │ ├── StringReceivePacket.java
│ │ │ │ └── StringSendPacket.java
│ │ │ │ ├── core
│ │ │ │ ├── BlinkConn.java
│ │ │ │ ├── BlinkPacket.java
│ │ │ │ ├── EntityNode.java
│ │ │ │ ├── HeadNode.java
│ │ │ │ ├── ReceiveDelivery.java
│ │ │ │ ├── ReceiveDispatcher.java
│ │ │ │ ├── ReceivePacket.java
│ │ │ │ ├── ReceiveParser.java
│ │ │ │ ├── Receiver.java
│ │ │ │ ├── Resource.java
│ │ │ │ ├── SendDelivery.java
│ │ │ │ ├── SendDispatcher.java
│ │ │ │ ├── SendPacket.java
│ │ │ │ └── Sender.java
│ │ │ │ └── listener
│ │ │ │ ├── ReceiveListener.java
│ │ │ │ └── SendListener.java
│ │ │ └── res
│ │ │ └── values
│ │ │ └── strings.xml
│ ├── sample
│ │ ├── .gitignore
│ │ ├── build.gradle
│ │ ├── proguard-rules.pro
│ │ └── src
│ │ │ ├── androidTest
│ │ │ └── java
│ │ │ │ └── net
│ │ │ │ └── qiujuer
│ │ │ │ └── sample
│ │ │ │ └── blink
│ │ │ │ └── ApplicationTest.java
│ │ │ └── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── java
│ │ │ └── net
│ │ │ │ └── qiujuer
│ │ │ │ └── sample
│ │ │ │ └── blink
│ │ │ │ └── MainActivity.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
│ └── settings.gradle
└── Sample
│ └── Client.apk
├── Art
├── Client.png
├── FlowChart.png
├── Logo.png
├── Server.png
└── Src
│ ├── Blink.bmpr
│ └── Logo.ai
├── C Sharp
├── Blink
│ ├── .gitignore
│ ├── Blink.sln
│ ├── Blink.v12.suo
│ ├── Blink
│ │ ├── Async
│ │ │ ├── AsyncAbsDispatcher.cs
│ │ │ ├── AsyncReceiveDispatcher.cs
│ │ │ ├── AsyncSendDispatcher.cs
│ │ │ ├── AsyncSocketAdapter.cs
│ │ │ └── SocketAsyncEventArgsPool.cs
│ │ ├── Blink.cs
│ │ ├── Blink.csproj
│ │ ├── Blink_Key.pfx
│ │ ├── Box
│ │ │ ├── BaseReceivePacket.cs
│ │ │ ├── BaseSendPacket.cs
│ │ │ ├── ByteReceivePacket.cs
│ │ │ ├── ByteSendPacket.cs
│ │ │ ├── FileReceivePacket.cs
│ │ │ ├── FileSendPacket.cs
│ │ │ ├── StringReceivePacket.cs
│ │ │ └── StringSendPacket.cs
│ │ ├── ClassDiagram1.cd
│ │ ├── Core
│ │ │ ├── BlinkConn.cs
│ │ │ ├── BlinkDelivery.cs
│ │ │ ├── BlinkPacket.cs
│ │ │ ├── BlinkParser.cs
│ │ │ ├── Packet.cs
│ │ │ ├── ReceiveDelivery.cs
│ │ │ ├── ReceivePacket.cs
│ │ │ ├── Receiver.cs
│ │ │ ├── Resource.cs
│ │ │ ├── SendDelivery.cs
│ │ │ ├── SendPacket.cs
│ │ │ └── Sender.cs
│ │ ├── Kit
│ │ │ ├── BlinkLog.cs
│ │ │ ├── BlinkParserImpl.cs
│ │ │ ├── CallBackDelivery.cs
│ │ │ ├── DelegateDelivery.cs
│ │ │ ├── DiskResource.cs
│ │ │ ├── EventDelivery.cs
│ │ │ └── Runnable.cs
│ │ ├── Listener
│ │ │ ├── BlinkListener.cs
│ │ │ ├── ReceiveListener.cs
│ │ │ └── SendListener.cs
│ │ └── Properties
│ │ │ └── AssemblyInfo.cs
│ ├── BlinkTest
│ │ ├── .gitignore
│ │ ├── App.config
│ │ ├── BlinkTest.csproj
│ │ ├── Program.cs
│ │ └── Properties
│ │ │ └── AssemblyInfo.cs
│ ├── Client
│ │ ├── .gitignore
│ │ ├── App.config
│ │ ├── Client.csproj
│ │ ├── Program.cs
│ │ ├── Properties
│ │ │ └── AssemblyInfo.cs
│ │ └── SendCallBack.cs
│ └── Server
│ │ ├── .gitignore
│ │ ├── App.config
│ │ ├── BlinkCallBack.cs
│ │ ├── Program.cs
│ │ ├── Properties
│ │ └── AssemblyInfo.cs
│ │ └── Server.csproj
└── Sample
│ ├── Client
│ ├── Blink.dll
│ └── Client.exe
│ └── Server
│ ├── Blink.dll
│ └── Server.exe
├── Java
├── Blink
│ ├── .gitignore
│ ├── build.gradle
│ ├── gradlew
│ ├── gradlew.bat
│ ├── library
│ │ ├── .classpath
│ │ ├── .project
│ │ ├── .settings
│ │ │ └── org.eclipse.jdt.core.prefs
│ │ ├── build.gradle
│ │ └── src
│ │ │ └── net
│ │ │ └── qiujuer
│ │ │ └── blink
│ │ │ ├── BlinkClient.java
│ │ │ ├── BlinkConnect.java
│ │ │ ├── BlinkServer.java
│ │ │ ├── async
│ │ │ ├── AsyncDispatcher.java
│ │ │ ├── AsyncFormatter.java
│ │ │ ├── AsyncParser.java
│ │ │ ├── AsyncReceiveDispatcher.java
│ │ │ ├── AsyncSendDispatcher.java
│ │ │ ├── AsyncSocketAdapter.java
│ │ │ ├── IoEventArgs.java
│ │ │ └── SelectorFactory.java
│ │ │ ├── box
│ │ │ ├── BaseReceivePacket.java
│ │ │ ├── BaseSendPacket.java
│ │ │ ├── ByteReceivePacket.java
│ │ │ ├── ByteSendPacket.java
│ │ │ ├── FileReceivePacket.java
│ │ │ ├── FileSendPacket.java
│ │ │ ├── StringReceivePacket.java
│ │ │ └── StringSendPacket.java
│ │ │ ├── core
│ │ │ ├── BlinkParser.java
│ │ │ ├── Connector.java
│ │ │ ├── ExecutorDelivery.java
│ │ │ ├── Packet.java
│ │ │ ├── PacketFilter.java
│ │ │ ├── PacketFormatter.java
│ │ │ ├── PacketParser.java
│ │ │ ├── PacketType.java
│ │ │ ├── ReceiveDispatcher.java
│ │ │ ├── ReceivePacket.java
│ │ │ ├── Receiver.java
│ │ │ ├── SendDispatcher.java
│ │ │ ├── SendPacket.java
│ │ │ ├── Sender.java
│ │ │ ├── delivery
│ │ │ │ ├── ConnectDelivery.java
│ │ │ │ ├── ReceiveDelivery.java
│ │ │ │ └── SendDelivery.java
│ │ │ └── listener
│ │ │ │ ├── ConnectListener.java
│ │ │ │ ├── ReceiveListener.java
│ │ │ │ └── SendListener.java
│ │ │ └── kit
│ │ │ ├── BlinkParserImpl.java
│ │ │ ├── DiskResource.java
│ │ │ ├── Disposable.java
│ │ │ ├── Resource.java
│ │ │ └── convert
│ │ │ ├── BitConverter.java
│ │ │ └── HashConverter.java
│ ├── sample
│ │ ├── .classpath
│ │ ├── .project
│ │ ├── .settings
│ │ │ └── org.eclipse.jdt.core.prefs
│ │ ├── build.gradle
│ │ └── src
│ │ │ └── net
│ │ │ └── qiujuer
│ │ │ └── sample
│ │ │ └── blink
│ │ │ ├── CallBack.java
│ │ │ ├── Client.java
│ │ │ ├── Server.java
│ │ │ └── Utils.java
│ └── settings.gradle
└── Sample
│ └── Sample.zip
├── LICENSE
├── README.md
└── Release
├── Android
├── Blink.jar
└── blink.aar
├── C Sharp
└── 1.0.0.0
│ ├── Blink.dll
│ └── Blink.pdb
└── Java
└── blink.jar
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.ap_
3 |
4 | # Files for the Dalvik VM
5 | *.dex
6 |
7 | # Java class files
8 | *.class
9 |
10 | # Generated files
11 | bin/
12 | gen/
13 | obj/
14 |
15 | # Gradle files
16 | .gradle/
17 | build/
18 | /*/build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
--------------------------------------------------------------------------------
/Android/Blink/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/
4 | /gradle
5 | .DS_Store
6 | /build
7 | /captures
8 | *.iml
--------------------------------------------------------------------------------
/Android/Blink/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.3.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Android/Blink/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/Android/Blink/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/Android/Blink/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/Android/Blink/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 22
5 | buildToolsVersion "22.0.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 22
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | task clear(type: Delete) {
22 | delete '../../../Release/Android/blink.jar'
23 | delete '../../../Release/Android/blink.aar'
24 | }
25 |
26 | task make(type: Copy) {
27 | // Jar
28 | from('build/intermediates/bundles/release/')
29 | into('../../../Release/Android/')
30 | include('classes.jar')
31 | rename('classes.jar', 'blink.jar')
32 | // aar
33 | from('build/outputs/aar/')
34 | into('../../../Release/Android/')
35 | include('library-release.aar')
36 | rename('library-release.aar', 'blink.aar')
37 | }
38 | make.dependsOn(clear, build)
--------------------------------------------------------------------------------
/Android/Blink/library/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:\ToolKits\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 |
--------------------------------------------------------------------------------
/Android/Blink/library/src/androidTest/java/net/qiujuer/blink/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.blink;
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 | }
--------------------------------------------------------------------------------
/Android/Blink/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Android/Blink/library/src/main/java/net/qiujuer/blink/box/BaseReceivePacket.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.box;
21 |
22 | import net.qiujuer.blink.core.ReceivePacket;
23 |
24 | import java.io.OutputStream;
25 |
26 | /**
27 | * The Receive base class
28 | */
29 | public abstract class BaseReceivePacket extends ReceivePacket {
30 | protected OutputStream mStream;
31 | protected T mEntity;
32 |
33 | public BaseReceivePacket(long id, byte type, long len) {
34 | super(id, type, len);
35 | }
36 |
37 | public T getEntity() {
38 | return mEntity;
39 | }
40 |
41 | @Override
42 | public void write(byte[] buffer, int offset, int count) {
43 | OutputStream stream = mStream;
44 | if (stream != null) {
45 | try {
46 | stream.write(buffer, offset, count);
47 | stream.flush();
48 | } catch (Exception e) {
49 | e.printStackTrace();
50 | }
51 | }
52 | }
53 |
54 | protected void closeStream() {
55 | OutputStream stream = mStream;
56 | mStream = null;
57 | if (stream != null) {
58 | try {
59 | stream.flush();
60 | stream.close();
61 | } catch (Exception e) {
62 | e.printStackTrace();
63 | }
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/Android/Blink/library/src/main/java/net/qiujuer/blink/box/BaseSendPacket.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.box;
21 |
22 | import net.qiujuer.blink.core.SendPacket;
23 | import net.qiujuer.blink.listener.SendListener;
24 |
25 | import java.io.InputStream;
26 |
27 | /**
28 | * The Send base class
29 | */
30 | public abstract class BaseSendPacket extends SendPacket {
31 | protected T mEntity;
32 | protected InputStream mStream;
33 |
34 | public BaseSendPacket(T entity, byte type, SendListener listener) {
35 | super(type, listener);
36 | mEntity = entity;
37 | }
38 |
39 |
40 | public T getEntity() {
41 | return mEntity;
42 | }
43 |
44 | @Override
45 | public int read(byte[] buffer, int offset, int count) {
46 | InputStream stream = mStream;
47 | if (stream == null)
48 | return -1;
49 | try {
50 | return stream.read(buffer, offset, count);
51 | } catch (Exception e) {
52 | return -1;
53 | }
54 | }
55 |
56 | protected void closeStream() {
57 | InputStream stream = mStream;
58 | mStream = null;
59 | if (stream != null) {
60 | try {
61 | stream.close();
62 | } catch (Exception e) {
63 | e.printStackTrace();
64 | }
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/Android/Blink/library/src/main/java/net/qiujuer/blink/box/ByteReceivePacket.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.box;
21 |
22 | import java.io.ByteArrayOutputStream;
23 |
24 | /**
25 | * Bytes receive class
26 | */
27 | public class ByteReceivePacket extends BaseReceivePacket {
28 | public ByteReceivePacket(long id, byte type, long len) {
29 | super(id, type, len);
30 | }
31 |
32 | @Override
33 | public boolean startPacket() {
34 | try {
35 | mStream = new ByteArrayOutputStream((int) getLength());
36 | return true;
37 | } catch (Exception e) {
38 | return false;
39 | }
40 | }
41 |
42 | @Override
43 | public void endPacket() {
44 | if (mStream != null) {
45 | mEntity = ((ByteArrayOutputStream) mStream).toByteArray();
46 | closeStream();
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Android/Blink/library/src/main/java/net/qiujuer/blink/box/ByteSendPacket.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.box;
21 |
22 | import net.qiujuer.blink.listener.SendListener;
23 |
24 | import java.io.ByteArrayInputStream;
25 |
26 | /**
27 | * Bytes send class
28 | */
29 | public class ByteSendPacket extends BaseSendPacket {
30 | public ByteSendPacket(byte[] entity) {
31 | this(entity, null);
32 | }
33 |
34 | public ByteSendPacket(byte[] entity, SendListener listener) {
35 | super(entity, PacketType.BYTES, listener);
36 | mLength = mEntity.length;
37 | }
38 |
39 | @Override
40 | public boolean startPacket() {
41 | try {
42 | mStream = new ByteArrayInputStream(mEntity);
43 | return true;
44 | } catch (Exception e) {
45 | return false;
46 | }
47 | }
48 |
49 | @Override
50 | public void endPacket() {
51 | closeStream();
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/Android/Blink/library/src/main/java/net/qiujuer/blink/box/FileSendPacket.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.box;
21 |
22 | import net.qiujuer.blink.listener.SendListener;
23 |
24 | import java.io.File;
25 | import java.io.FileInputStream;
26 | import java.io.FileNotFoundException;
27 |
28 | /**
29 | * File send class
30 | */
31 | public class FileSendPacket extends BaseSendPacket {
32 |
33 | public FileSendPacket(File file) {
34 | this(file, null);
35 | }
36 |
37 | public FileSendPacket(File entity, SendListener listener) {
38 | super(entity, PacketType.FILE, listener);
39 | mLength = mEntity.length();
40 | }
41 |
42 | @Override
43 | public boolean startPacket() {
44 | try {
45 | mStream = new FileInputStream(mEntity);
46 | return true;
47 | } catch (FileNotFoundException e) {
48 | return false;
49 | }
50 | }
51 |
52 | @Override
53 | public void endPacket() {
54 | closeStream();
55 | }
56 |
57 | @Override
58 | public short readInfo(byte[] buffer, int index) {
59 | try {
60 | byte[] info = mEntity.getName().getBytes("UTF-8");
61 | short len = (short) info.length;
62 | System.arraycopy(info, 0, buffer, index, len);
63 | return len;
64 | } catch (Exception e) {
65 | return 0;
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/Android/Blink/library/src/main/java/net/qiujuer/blink/box/StringReceivePacket.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.box;
21 |
22 | import java.io.ByteArrayOutputStream;
23 | import java.io.UnsupportedEncodingException;
24 |
25 | /**
26 | * String receive class
27 | */
28 | public class StringReceivePacket extends BaseReceivePacket {
29 | public StringReceivePacket(long id, byte type, long len) {
30 | super(id, type, len);
31 | }
32 |
33 | @Override
34 | public boolean startPacket() {
35 | try {
36 | mStream = new ByteArrayOutputStream((int) getLength());
37 | return true;
38 | } catch (Exception e) {
39 | return false;
40 | }
41 | }
42 |
43 | @Override
44 | public void endPacket() {
45 | if (mStream != null) {
46 | byte[] bytes = ((ByteArrayOutputStream) mStream).toByteArray();
47 | try {
48 | mEntity = new String(bytes, 0, bytes.length, "UTF-8");
49 | } catch (UnsupportedEncodingException e) {
50 | e.printStackTrace();
51 | }
52 |
53 | closeStream();
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/Android/Blink/library/src/main/java/net/qiujuer/blink/box/StringSendPacket.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.box;
21 |
22 | import net.qiujuer.blink.listener.SendListener;
23 |
24 | import java.io.UnsupportedEncodingException;
25 |
26 | /**
27 | * String send class
28 | */
29 | public class StringSendPacket extends ByteSendPacket {
30 | public StringSendPacket(String entity) throws UnsupportedEncodingException {
31 | this(entity, null);
32 | }
33 |
34 | public StringSendPacket(String entity, SendListener listener) throws UnsupportedEncodingException {
35 | super(entity.getBytes("UTF-8"), listener);
36 |
37 | mType = PacketType.STRING;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Android/Blink/library/src/main/java/net/qiujuer/blink/core/BlinkDelivery.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | import net.qiujuer.blink.kit.Disposable;
23 |
24 | /**
25 | * Blink status delivery interface
26 | */
27 | public interface BlinkDelivery extends Disposable {
28 | /**
29 | * On Socket Disconnect Post CallBack
30 | */
31 | void postBlinkDisconnect();
32 | }
33 |
--------------------------------------------------------------------------------
/Android/Blink/library/src/main/java/net/qiujuer/blink/core/BlinkPacket.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | /**
23 | * Blink Data Packet
24 | */
25 | public abstract class BlinkPacket implements Packet {
26 | private boolean mSucceed;
27 | protected byte mType;
28 | protected long mLength;
29 |
30 | public BlinkPacket(byte type) {
31 | mType = type;
32 | }
33 |
34 |
35 | @Override
36 | public byte getPacketType() {
37 | return mType;
38 | }
39 |
40 | @Override
41 | public long getLength() {
42 | return mLength;
43 | }
44 |
45 | @Override
46 | public void setSuccess(boolean isSuccess) {
47 | mSucceed = isSuccess;
48 | }
49 |
50 | @Override
51 | public boolean isSucceed() {
52 | return mSucceed;
53 | }
54 |
55 | /**
56 | * On Send or Receive start call this
57 | *
58 | * @return Init status
59 | */
60 | public abstract boolean startPacket();
61 |
62 | /**
63 | * On Send or Receive end call this
64 | */
65 | public abstract void endPacket();
66 |
67 | /**
68 | * Blink Packet Type
69 | */
70 | public static class PacketType {
71 | public final static byte STRING = 1;
72 | public final static byte BYTES = 2;
73 | public final static byte FILE = 3;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/Android/Blink/library/src/main/java/net/qiujuer/blink/core/BlinkParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | /**
23 | * Blink parse interface
24 | */
25 | public interface BlinkParser {
26 |
27 | /**
28 | * Parse receiver receive data
29 | *
30 | * @param type Data type
31 | * @param len Data Len
32 | * @return ReceivePacket
33 | */
34 | ReceivePacket parseReceive(byte type, long len);
35 | }
36 |
--------------------------------------------------------------------------------
/Android/Blink/library/src/main/java/net/qiujuer/blink/core/Packet.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | /**
23 | * Bink Packet Interface
24 | */
25 | public interface Packet {
26 |
27 | /**
28 | * Get packet type
29 | *
30 | * @return Type
31 | */
32 | byte getPacketType();
33 |
34 | /**
35 | * Get packet length
36 | *
37 | * @return Size
38 | */
39 | long getLength();
40 |
41 | /**
42 | * Set packet send or receive status
43 | *
44 | * @param isSuccess Status
45 | */
46 | void setSuccess(boolean isSuccess);
47 |
48 | /**
49 | * Get the packet is succeed
50 | *
51 | * @return Status
52 | */
53 | boolean isSucceed();
54 | }
55 |
--------------------------------------------------------------------------------
/Android/Blink/library/src/main/java/net/qiujuer/blink/core/ReceiveDelivery.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | /**
23 | * Receiver delivery interface
24 | */
25 | public interface ReceiveDelivery {
26 | /**
27 | * Parses a start response from the receiver.
28 | *
29 | * @param entity ReceivePacket
30 | */
31 | void postReceiveStart(ReceivePacket entity);
32 |
33 | /**
34 | * Parses a end response from the receiver.
35 | *
36 | * @param entity ReceivePacket
37 | * @param isSuccess isSuccess
38 | */
39 | void postReceiveEnd(ReceivePacket entity, boolean isSuccess);
40 |
41 | /**
42 | * Parses a progress response from the receiver.
43 | *
44 | * @param entity ReceivePacket
45 | * @param progress Receive progress
46 | */
47 | void postReceiveProgress(ReceivePacket entity, float progress);
48 | }
49 |
--------------------------------------------------------------------------------
/Android/Blink/library/src/main/java/net/qiujuer/blink/core/ReceivePacket.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | /**
23 | * Receive Packet
24 | */
25 | public abstract class ReceivePacket extends BlinkPacket {
26 | private final long mId;
27 | private String mHash;
28 |
29 | public ReceivePacket(long id, byte type, long len) {
30 | super(type);
31 | mId = id;
32 | mLength = len;
33 | }
34 |
35 | public long getId() {
36 | return mId;
37 | }
38 |
39 | /**
40 | * Set Packet Hash Code
41 | *
42 | * @param hashCode HashCode
43 | */
44 | public void setHash(String hashCode) {
45 | mHash = hashCode;
46 | }
47 |
48 | /**
49 | * Get Packet Hash Code
50 | *
51 | * @return HashCode
52 | */
53 | public String getHash() {
54 | return mHash;
55 | }
56 |
57 | /**
58 | * On Receiver receive same info buffer call this
59 | *
60 | * @param buffer Info data
61 | * @param offset Buffer offset
62 | * @param count Buffer Count
63 | */
64 | public void writeInfo(byte[] buffer, int offset, int count) {
65 | }
66 |
67 | /**
68 | * Receiver write buffer
69 | *
70 | * @param buffer Buffer
71 | * @param offset Buffer offset
72 | * @param count Buffer Count
73 | */
74 | public abstract void write(byte[] buffer, int offset, int count);
75 | }
76 |
--------------------------------------------------------------------------------
/Android/Blink/library/src/main/java/net/qiujuer/blink/core/Receiver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | import net.qiujuer.blink.async.AsyncEventArgs;
23 | import net.qiujuer.blink.kit.Disposable;
24 |
25 | /**
26 | * This socket receiver
27 | */
28 | public interface Receiver extends Disposable {
29 | /**
30 | * Get receive buffer size
31 | *
32 | * @return Buffer Size
33 | */
34 | int getReceiveBufferSize();
35 |
36 | /**
37 | * Async receive same data to buffer
38 | *
39 | * @param e SocketAsyncEventArgs
40 | * @return Status
41 | */
42 | boolean receiveAsync(AsyncEventArgs e);
43 | }
44 |
--------------------------------------------------------------------------------
/Android/Blink/library/src/main/java/net/qiujuer/blink/core/Resource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | import java.io.File;
23 |
24 | /**
25 | * Blink Files Resource
26 | */
27 | public interface Resource {
28 | /**
29 | * Create a file from resource.
30 | *
31 | * @return New file path
32 | */
33 | File create(long id);
34 |
35 | /**
36 | * Empties the resource by oneself
37 | */
38 | void clear();
39 |
40 | /**
41 | * Empties the resource by the path
42 | */
43 | void clearAll();
44 |
45 | /**
46 | * Get the Mark
47 | *
48 | * @return Receive Mark
49 | */
50 | String getMark();
51 | }
52 |
--------------------------------------------------------------------------------
/Android/Blink/library/src/main/java/net/qiujuer/blink/core/SendDelivery.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | import net.qiujuer.blink.kit.Disposable;
23 |
24 | /**
25 | * Send delivery interface
26 | */
27 | public interface SendDelivery extends Disposable {
28 |
29 | /**
30 | * Parses a progress response from the sender.
31 | *
32 | * @param entity SendPacket
33 | * @param progress Send progress
34 | */
35 | void postSendProgress(SendPacket entity, float progress);
36 | }
37 |
--------------------------------------------------------------------------------
/Android/Blink/library/src/main/java/net/qiujuer/blink/core/SendPacket.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | import net.qiujuer.blink.listener.SendListener;
23 |
24 | /**
25 | * Blink SendPacket
26 | */
27 | public abstract class SendPacket extends BlinkPacket {
28 | private final SendListener mListener;
29 | private boolean mCanceled;
30 | private BlinkConn mBlinkConn;
31 |
32 |
33 | public SendPacket(byte type, SendListener listener) {
34 | super(type);
35 | mListener = listener;
36 | }
37 |
38 | public SendListener getListener() {
39 | return mListener;
40 | }
41 |
42 | /**
43 | * Cancel the packet to send
44 | * If the packet on sending you can't cancel it
45 | * But you can cancel sending notify callback
46 | */
47 | public void cancel() {
48 | mCanceled = true;
49 | if (mBlinkConn != null) {
50 | mBlinkConn.cancel(this);
51 | mBlinkConn = null;
52 | }
53 | }
54 |
55 | /**
56 | * Get the packet iscanceled
57 | *
58 | * @return Is Canceled
59 | */
60 | public boolean isCanceled() {
61 | return mCanceled;
62 | }
63 |
64 | /**
65 | * Set The BlinkConn to Cancel from queue
66 | *
67 | * @param blinkConn BlinkConn
68 | * @return SendPacket
69 | */
70 | SendPacket setBlinkConn(BlinkConn blinkConn) {
71 | mBlinkConn = blinkConn;
72 | return this;
73 | }
74 |
75 | /**
76 | * On Sender send the packet call this to send packet info
77 | * The bytes in 0~32767 size
78 | *
79 | * @param buffer Send buffer
80 | * @param index Buffer start index
81 | * @return Read to buffer count
82 | */
83 | public short readInfo(byte[] buffer, int index) {
84 | return 0;
85 | }
86 |
87 | /**
88 | * Sender read same data to send
89 | *
90 | * @param buffer Buffer
91 | * @param offset Buffer offset
92 | * @param count Buffer count
93 | * @return Read to buffer count
94 | */
95 | public abstract int read(byte[] buffer, int offset, int count);
96 | }
97 |
--------------------------------------------------------------------------------
/Android/Blink/library/src/main/java/net/qiujuer/blink/core/Sender.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | import net.qiujuer.blink.async.AsyncEventArgs;
23 | import net.qiujuer.blink.kit.Disposable;
24 |
25 | /**
26 | * This socket sender
27 | */
28 | public interface Sender extends Disposable {
29 | /**
30 | * Get socket send buffer size
31 | *
32 | * @return Buffer Size
33 | */
34 | int getSendBufferSize();
35 |
36 | /**
37 | * Async send same byte
38 | *
39 | * @param e SocketAsyncEventArgs
40 | * @return Status
41 | */
42 | boolean sendAsync(AsyncEventArgs e);
43 | }
44 |
--------------------------------------------------------------------------------
/Android/Blink/library/src/main/java/net/qiujuer/blink/kit/BlinkParserImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.kit;
21 |
22 | import net.qiujuer.blink.box.ByteReceivePacket;
23 | import net.qiujuer.blink.box.FileReceivePacket;
24 | import net.qiujuer.blink.box.StringReceivePacket;
25 | import net.qiujuer.blink.core.BlinkPacket;
26 | import net.qiujuer.blink.core.BlinkParser;
27 | import net.qiujuer.blink.core.ReceivePacket;
28 | import net.qiujuer.blink.core.Resource;
29 |
30 | import java.io.File;
31 |
32 |
33 | public class BlinkParserImpl implements BlinkParser {
34 | private long mId = 0;
35 | protected Resource mResource;
36 |
37 | public BlinkParserImpl(Resource resource) {
38 | mResource = resource;
39 | }
40 |
41 | @Override
42 | public ReceivePacket parseReceive(byte type, long len) {
43 | long id = ++mId;
44 | ReceivePacket packet = null;
45 | switch (type) {
46 | case BlinkPacket.PacketType.STRING:
47 | packet = new StringReceivePacket(id, type, len);
48 | break;
49 | case BlinkPacket.PacketType.BYTES:
50 | packet = new ByteReceivePacket(id, type, len);
51 | break;
52 | case BlinkPacket.PacketType.FILE:
53 | File file = mResource.create(id);
54 | if (file != null)
55 | packet = new FileReceivePacket(id, type, len, file);
56 | break;
57 | }
58 | return packet;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/Android/Blink/library/src/main/java/net/qiujuer/blink/kit/Disposable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.kit;
21 |
22 | /**
23 | * Define a way to release resources allocated.
24 | */
25 | public interface Disposable {
26 | /**
27 | * Perform related to release or reset unmanaged resources application defined tasks.
28 | */
29 | void dispose();
30 | }
31 |
--------------------------------------------------------------------------------
/Android/Blink/library/src/main/java/net/qiujuer/blink/kit/HashConverter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.kit;
21 |
22 | /**
23 | * Hash Converter
24 | */
25 | public class HashConverter {
26 | private static final char HEX_DIGITS[] = {'0', '1', '2', '3', '4', '5',
27 | '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
28 |
29 | /**
30 | * Convert bytes to md5 string
31 | *
32 | * @param b bytes
33 | * @return md5
34 | */
35 | public static String toMd5(byte[] b) {
36 | StringBuilder sb = new StringBuilder(b.length * 2);
37 | for (byte a : b) {
38 | sb.append(HEX_DIGITS[(a & 0xf0) >>> 4]);
39 | sb.append(HEX_DIGITS[a & 0x0f]);
40 | }
41 | return sb.toString();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Android/Blink/library/src/main/java/net/qiujuer/blink/listener/BlinkListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.listener;
21 |
22 | /**
23 | * Blink notify listener
24 | */
25 | public interface BlinkListener {
26 |
27 | /**
28 | * On Receive or Sender error by socket err call this
29 | */
30 | void onBlinkDisconnect();
31 | }
32 |
--------------------------------------------------------------------------------
/Android/Blink/library/src/main/java/net/qiujuer/blink/listener/ReceiveListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.listener;
21 |
22 | import net.qiujuer.blink.core.ReceivePacket;
23 |
24 | /**
25 | * Receive notify listener
26 | */
27 | public interface ReceiveListener {
28 | /**
29 | * On Receiver receive new packet call this
30 | *
31 | * @param type Packet Type
32 | * @param id Packet Id
33 | */
34 | void onReceiveStart(byte type, long id);
35 |
36 | /**
37 | * Receiver receive packet progress
38 | *
39 | * @param packet ReceivePacket
40 | * @param progress Receive Progress
41 | */
42 | void onReceiveProgress(ReceivePacket packet, float progress);
43 |
44 | /**
45 | * On Receiver end receive packet call this
46 | *
47 | * @param packet ReceivePacket
48 | */
49 | void onReceiveEnd(ReceivePacket packet);
50 | }
51 |
--------------------------------------------------------------------------------
/Android/Blink/library/src/main/java/net/qiujuer/blink/listener/SendListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.listener;
21 |
22 | /**
23 | * Send notify listener
24 | */
25 | public interface SendListener {
26 | /**
27 | * On sender send the packet call this
28 | * On start progress == 0
29 | * On end progress ==1
30 | *
31 | * @param progress Send progress (0~1)
32 | */
33 | void onSendProgress(float progress);
34 | }
35 |
--------------------------------------------------------------------------------
/Android/Blink/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | library
3 |
4 |
--------------------------------------------------------------------------------
/Android/Blink/old/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/Android/Blink/old/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 22
5 | buildToolsVersion "22.0.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 22
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | task clearJar(type: Delete) {
22 | delete '../../Release/blink_android.jar'
23 | }
24 |
25 | task makeJar(type: Copy) {
26 | from('build/intermediates/bundles/release/')
27 | into('../../Release/')
28 | include('classes.jar')
29 | rename('classes.jar', 'blink_android.jar')
30 | }
31 | makeJar.dependsOn(clearJar, build)
--------------------------------------------------------------------------------
/Android/Blink/old/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:\ToolKits\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 |
--------------------------------------------------------------------------------
/Android/Blink/old/src/androidTest/java/net/qiujuer/blink/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.blink;
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 | }
--------------------------------------------------------------------------------
/Android/Blink/old/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Android/Blink/old/src/main/java/net/qiujuer/blink/box/ByteReceivePacket.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 03/31/2015
5 | * Changed 04/02/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.box;
21 |
22 | import net.qiujuer.blink.core.ReceivePacket;
23 |
24 | import java.io.ByteArrayOutputStream;
25 |
26 | /**
27 | * Bytes receive class
28 | */
29 | public class ByteReceivePacket extends ReceivePacket {
30 |
31 | public ByteReceivePacket(long id, int type, int len) {
32 | super(id, type, len);
33 | }
34 |
35 |
36 | @Override
37 | protected void adjustStream() {
38 | mOutStream = new ByteArrayOutputStream(getLength());
39 | }
40 |
41 | @Override
42 | protected void adjustPacket() {
43 | if (mOutStream != null) {
44 | mEntity = ((ByteArrayOutputStream) mOutStream).toByteArray();
45 | mOutStream = null;
46 | }
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/Android/Blink/old/src/main/java/net/qiujuer/blink/box/ByteSendPacket.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 03/31/2015
5 | * Changed 04/02/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.box;
21 |
22 | import net.qiujuer.blink.core.SendPacket;
23 | import net.qiujuer.blink.listener.SendListener;
24 |
25 | import java.io.ByteArrayInputStream;
26 | import java.io.InputStream;
27 |
28 | /**
29 | * Bytes send class
30 | */
31 | public class ByteSendPacket extends SendPacket {
32 |
33 | public ByteSendPacket(byte[] entity) {
34 | this(entity, null);
35 | }
36 |
37 | public ByteSendPacket(byte[] entity, SendListener listener) {
38 | super(Type.BYTES, entity, listener);
39 | mLength = mEntity.length;
40 | }
41 |
42 | @Override
43 | public InputStream getInputStream() {
44 | return new ByteArrayInputStream(mEntity);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Android/Blink/old/src/main/java/net/qiujuer/blink/box/FileReceivePacket.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 03/31/2015
5 | * Changed 04/02/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.box;
21 |
22 | import net.qiujuer.blink.core.ReceivePacket;
23 |
24 | import java.io.File;
25 | import java.io.FileNotFoundException;
26 | import java.io.FileOutputStream;
27 |
28 | /**
29 | * File receive class
30 | */
31 | public class FileReceivePacket extends ReceivePacket {
32 | public FileReceivePacket(long id, int type, int len, File file) {
33 | super(id, type, len);
34 | mEntity = file;
35 | }
36 |
37 | @Override
38 | protected void adjustStream() {
39 | try {
40 | mOutStream = new FileOutputStream(mEntity);
41 | } catch (FileNotFoundException e) {
42 | e.printStackTrace();
43 | }
44 | }
45 |
46 | @Override
47 | protected void adjustPacket() {
48 | mOutStream = null;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/Android/Blink/old/src/main/java/net/qiujuer/blink/box/FileSendPacket.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 03/31/2015
5 | * Changed 04/02/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.box;
21 |
22 | import net.qiujuer.blink.core.SendPacket;
23 | import net.qiujuer.blink.listener.SendListener;
24 |
25 | import java.io.File;
26 | import java.io.FileInputStream;
27 | import java.io.FileNotFoundException;
28 | import java.io.InputStream;
29 |
30 | /**
31 | * File send class
32 | */
33 | public class FileSendPacket extends SendPacket {
34 |
35 | public FileSendPacket(File file) {
36 | this(file, null);
37 | }
38 |
39 | public FileSendPacket(File entity, SendListener listener) {
40 | super(Type.FILE, entity, listener);
41 | }
42 |
43 | @Override
44 | public InputStream getInputStream() {
45 | try {
46 | return new FileInputStream(mEntity);
47 | } catch (FileNotFoundException e) {
48 | return null;
49 | }
50 | }
51 |
52 | @Override
53 | public int getLength() {
54 | return (int) mEntity.length();
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/Android/Blink/old/src/main/java/net/qiujuer/blink/box/StringReceivePacket.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 03/31/2015
5 | * Changed 04/02/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.box;
21 |
22 | import net.qiujuer.blink.core.ReceivePacket;
23 |
24 | import java.io.ByteArrayOutputStream;
25 | import java.io.UnsupportedEncodingException;
26 |
27 | /**
28 | * String receive class
29 | */
30 | public class StringReceivePacket extends ReceivePacket {
31 | public StringReceivePacket(long id, int type, int len) {
32 | super(id, type, len);
33 | }
34 |
35 | @Override
36 | protected void adjustStream() {
37 | mOutStream = new ByteArrayOutputStream(getLength());
38 | }
39 |
40 | @Override
41 | protected void adjustPacket() {
42 | if (mOutStream != null) {
43 | byte[] bytes = ((ByteArrayOutputStream) mOutStream).toByteArray();
44 | try {
45 | mEntity = new String(bytes, 0, bytes.length, "UTF-8");
46 | } catch (UnsupportedEncodingException e) {
47 | e.printStackTrace();
48 | }
49 | mOutStream = null;
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/Android/Blink/old/src/main/java/net/qiujuer/blink/box/StringSendPacket.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 03/31/2015
5 | * Changed 04/02/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.box;
21 |
22 | import net.qiujuer.blink.listener.SendListener;
23 |
24 | import java.io.UnsupportedEncodingException;
25 |
26 | /**
27 | * String send class
28 | */
29 | public class StringSendPacket extends ByteSendPacket {
30 |
31 | public StringSendPacket(String entity) throws UnsupportedEncodingException {
32 | this(entity, null);
33 | }
34 |
35 | public StringSendPacket(String entity, SendListener listener) throws UnsupportedEncodingException {
36 | super(entity.getBytes("UTF-8"), listener);
37 | mType = Type.STRING;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Android/Blink/old/src/main/java/net/qiujuer/blink/core/BlinkPacket.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 03/31/2015
5 | * Changed 04/02/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | /**
23 | * Blink Data Packet
24 | */
25 | public abstract class BlinkPacket extends EntityNode implements HeadNode {
26 | protected int mType;
27 | protected int mLength;
28 | private boolean mSucceed;
29 |
30 | public BlinkPacket(int type) {
31 | mType = type;
32 | }
33 |
34 | @Override
35 | public int getType() {
36 | return mType;
37 | }
38 |
39 | @Override
40 | public int getLength() {
41 | return mLength;
42 | }
43 |
44 | public void setSuccess(boolean isSuccess) {
45 | this.mSucceed = isSuccess;
46 | }
47 |
48 | public boolean isSucceed() {
49 | return mSucceed;
50 | }
51 |
52 | /**
53 | * Blink Entity Type
54 | */
55 | public interface Type {
56 | int STRING = 0;
57 | int BYTES = 1;
58 | int FILE = 2;
59 | }
60 |
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/Android/Blink/old/src/main/java/net/qiujuer/blink/core/EntityNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 03/31/2015
5 | * Changed 04/02/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | /**
23 | * Blink Entity Node
24 | */
25 | public abstract class EntityNode {
26 | protected T mEntity;
27 |
28 | public T getEntity() {
29 | return mEntity;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Android/Blink/old/src/main/java/net/qiujuer/blink/core/HeadNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 03/31/2015
5 | * Changed 04/02/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | /**
23 | * Bink Head Node
24 | */
25 | public interface HeadNode {
26 | int getType();
27 |
28 | int getLength();
29 | }
--------------------------------------------------------------------------------
/Android/Blink/old/src/main/java/net/qiujuer/blink/core/ReceiveDelivery.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 03/31/2015
5 | * Changed 04/02/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | import net.qiujuer.blink.listener.ReceiveListener;
23 |
24 | /**
25 | * Receiver delivery interface
26 | */
27 | public abstract class ReceiveDelivery {
28 | private final ReceiveListener mListener;
29 |
30 | public ReceiveDelivery(ReceiveListener listener) {
31 | mListener = listener;
32 | }
33 |
34 |
35 | /**
36 | * Get ReceiveListener
37 | *
38 | * @return ReceiveListener
39 | */
40 | protected ReceiveListener getReceiveListener() {
41 | return mListener;
42 | }
43 |
44 | /**
45 | * Parses a start response from the receiver.
46 | */
47 | public abstract void postReceiveStart(ReceivePacket entity);
48 |
49 | /**
50 | * Parses a end response from the receiver.
51 | */
52 | public abstract void postReceiveEnd(ReceivePacket entity, boolean isSuccess);
53 |
54 | /**
55 | * Parses a progress response from the receiver.
56 | */
57 | public abstract void postReceiveProgress(ReceivePacket entity, int total, int cur);
58 | }
59 |
--------------------------------------------------------------------------------
/Android/Blink/old/src/main/java/net/qiujuer/blink/core/ReceivePacket.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 03/31/2015
5 | * Changed 04/02/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | import java.io.OutputStream;
23 |
24 | /**
25 | * Receive Entity
26 | */
27 | public abstract class ReceivePacket extends BlinkPacket {
28 | private final long mId;
29 | protected OutputStream mOutStream;
30 | private String mHashCode;
31 |
32 | public ReceivePacket(long id, int type, int len) {
33 | super(type);
34 | mId = id;
35 | mLength = len;
36 | }
37 |
38 | public long getId() {
39 | return mId;
40 | }
41 |
42 | public OutputStream getOutputStream() {
43 | return mOutStream;
44 | }
45 |
46 | public void setHashCode(String hashCode) {
47 | mHashCode = hashCode;
48 | }
49 |
50 | public String getHashCode() {
51 | return mHashCode;
52 | }
53 |
54 | protected abstract void adjustStream();
55 |
56 | protected abstract void adjustPacket();
57 | }
58 |
--------------------------------------------------------------------------------
/Android/Blink/old/src/main/java/net/qiujuer/blink/core/ReceiveParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 03/31/2015
5 | * Changed 04/02/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | import net.qiujuer.blink.box.ByteReceivePacket;
23 | import net.qiujuer.blink.box.FileReceivePacket;
24 | import net.qiujuer.blink.box.StringReceivePacket;
25 |
26 | import java.io.File;
27 |
28 | /**
29 | * Blink receive entity parse
30 | */
31 | public class ReceiveParser {
32 | private long mId = 0;
33 | protected Resource mResource;
34 |
35 | public ReceiveParser(Resource resource) {
36 | mResource = resource;
37 | }
38 |
39 | public ReceivePacket> parseReceive(int type, int len) {
40 | final long id = ++mId;
41 | ReceivePacket> entity = null;
42 | switch (type) {
43 | case BlinkPacket.Type.STRING:
44 | entity = new StringReceivePacket(id, type, len);
45 | break;
46 | case BlinkPacket.Type.BYTES:
47 | entity = new ByteReceivePacket(id, type, len);
48 | break;
49 | case BlinkPacket.Type.FILE:
50 | File file = mResource.create(id);
51 | if (file != null)
52 | entity = new FileReceivePacket(id, type, len, file);
53 | break;
54 | }
55 | return entity;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/Android/Blink/old/src/main/java/net/qiujuer/blink/core/Receiver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 03/31/2015
5 | * Changed 04/02/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | /**
23 | * Receive entity interface
24 | */
25 | public interface Receiver {
26 |
27 | /**
28 | * Receive the entity's information
29 | *
30 | * @return ReceiveEntity
31 | */
32 | ReceivePacket> receiveHead();
33 |
34 |
35 | /**
36 | * Receive entity
37 | *
38 | * @param entity ReceiveEntity
39 | * @param delivery ReceiveDelivery
40 | * @return ReceiveEntity
41 | */
42 | boolean receiveEntity(ReceivePacket> entity, ReceiveDelivery delivery);
43 |
44 | /**
45 | * Destroy the receive IO stream
46 | */
47 | void destroyReceiveIO();
48 | }
49 |
--------------------------------------------------------------------------------
/Android/Blink/old/src/main/java/net/qiujuer/blink/core/Resource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 03/31/2015
5 | * Changed 04/02/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | import java.io.File;
23 |
24 | /**
25 | * Blink files Resource
26 | */
27 | public interface Resource {
28 | /**
29 | * Create a file from resource.
30 | *
31 | * @return New file
32 | */
33 | File create(long id);
34 |
35 | /**
36 | * Change a file name
37 | *
38 | * @param file File
39 | * @param newName New name
40 | * @return Status
41 | */
42 | boolean rename(File file, String newName);
43 |
44 |
45 | /**
46 | * Cut a file to new path
47 | *
48 | * @param oldFile File
49 | * @param newPath New path
50 | * @return New File
51 | */
52 | File cut(File oldFile, String newPath);
53 |
54 | /**
55 | * Cut a file to new path
56 | *
57 | * @param oldFile Old file
58 | * @param newFile New file
59 | * @return New file
60 | */
61 | File cut(File oldFile, File newFile);
62 |
63 |
64 | /**
65 | * Removes a file from the resource.
66 | *
67 | * @param name File name
68 | */
69 | void remove(String name);
70 |
71 | /**
72 | * Removes a file from the resource.
73 | *
74 | * @param file File
75 | */
76 | void remove(File file);
77 |
78 | /**
79 | * Empties the resource by oneself
80 | */
81 | void clear();
82 |
83 | /**
84 | * Empties the resource by the path
85 | */
86 | void clearAll();
87 |
88 | /**
89 | * Get the Mark
90 | *
91 | * @return T
92 | */
93 | T getMark();
94 | }
95 |
--------------------------------------------------------------------------------
/Android/Blink/old/src/main/java/net/qiujuer/blink/core/SendDelivery.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 03/31/2015
5 | * Changed 04/02/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | /**
23 | * Send delivery interface
24 | */
25 | public interface SendDelivery {
26 | /**
27 | * Parses a start response from the sender.
28 | */
29 | void postSendStart(SendPacket entity);
30 |
31 | /**
32 | * Parses a end response from the sender.
33 | */
34 | void postSendEnd(SendPacket entity, boolean isSuccess);
35 |
36 | /**
37 | * Parses a progress response from the sender.
38 | */
39 | void postSendProgress(SendPacket entity, int total, int cur);
40 | }
41 |
--------------------------------------------------------------------------------
/Android/Blink/old/src/main/java/net/qiujuer/blink/core/Sender.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 03/31/2015
5 | * Changed 04/02/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | /**
23 | * Send entity interface
24 | */
25 | public interface Sender {
26 |
27 | /**
28 | * Send the entity's information
29 | *
30 | * @param entity SendEntity
31 | * @return Status
32 | */
33 | boolean sendHead(SendPacket entity);
34 |
35 | /**
36 | * Send entity
37 | *
38 | * @param entity SendEntity
39 | * @return Status
40 | */
41 | boolean sendEntity(SendPacket entity, SendDelivery delivery);
42 |
43 | /**
44 | * Destroy the sender IO stream
45 | */
46 | void destroySendIO();
47 | }
48 |
--------------------------------------------------------------------------------
/Android/Blink/old/src/main/java/net/qiujuer/blink/listener/ReceiveListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 03/31/2015
5 | * Changed 04/02/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.listener;
21 |
22 | import net.qiujuer.blink.core.ReceivePacket;
23 |
24 | /**
25 | * Receive notify listener
26 | */
27 | public interface ReceiveListener {
28 | void onReceiveStart(int type, long id);
29 |
30 | void onReceiveProgress(int type, long id, int total, int cur);
31 |
32 | void onReceiveEnd(ReceivePacket entity);
33 | }
34 |
--------------------------------------------------------------------------------
/Android/Blink/old/src/main/java/net/qiujuer/blink/listener/SendListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 03/31/2015
5 | * Changed 04/02/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.listener;
21 |
22 | /**
23 | * Send notify listener
24 | */
25 | public interface SendListener {
26 | void onSendStart();
27 |
28 | void onSendProgress(int total, int cur);
29 |
30 | void onSendEnd(boolean isSuccess);
31 | }
--------------------------------------------------------------------------------
/Android/Blink/old/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Blink Library
3 |
4 |
--------------------------------------------------------------------------------
/Android/Blink/sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/Android/Blink/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 22
5 | buildToolsVersion "22.0.1"
6 |
7 | defaultConfig {
8 | applicationId "net.qiujuer.sample.blink"
9 | minSdkVersion 15
10 | targetSdkVersion 22
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:22.2.1'
25 | compile project(':library')
26 | }
27 |
--------------------------------------------------------------------------------
/Android/Blink/sample/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:\ToolKits\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 |
--------------------------------------------------------------------------------
/Android/Blink/sample/src/androidTest/java/net/qiujuer/sample/blink/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.sample.blink;
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 | }
--------------------------------------------------------------------------------
/Android/Blink/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
14 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Android/Blink/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
16 |
17 |
23 |
24 |
28 |
29 |
35 |
36 |
41 |
42 |
43 |
49 |
50 |
55 |
56 |
--------------------------------------------------------------------------------
/Android/Blink/sample/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/Android/Blink/sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujuer/Blink/1df33b2da92160b842faade83d4841a948788876/Android/Blink/sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Android/Blink/sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujuer/Blink/1df33b2da92160b842faade83d4841a948788876/Android/Blink/sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Android/Blink/sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujuer/Blink/1df33b2da92160b842faade83d4841a948788876/Android/Blink/sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Android/Blink/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujuer/Blink/1df33b2da92160b842faade83d4841a948788876/Android/Blink/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Android/Blink/sample/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/Android/Blink/sample/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/Android/Blink/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Blink
3 | Hello world!
4 | Settings
5 |
6 |
--------------------------------------------------------------------------------
/Android/Blink/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Android/Blink/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':sample', ':library', ':old'
2 |
--------------------------------------------------------------------------------
/Android/Sample/Client.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujuer/Blink/1df33b2da92160b842faade83d4841a948788876/Android/Sample/Client.apk
--------------------------------------------------------------------------------
/Art/Client.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujuer/Blink/1df33b2da92160b842faade83d4841a948788876/Art/Client.png
--------------------------------------------------------------------------------
/Art/FlowChart.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujuer/Blink/1df33b2da92160b842faade83d4841a948788876/Art/FlowChart.png
--------------------------------------------------------------------------------
/Art/Logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujuer/Blink/1df33b2da92160b842faade83d4841a948788876/Art/Logo.png
--------------------------------------------------------------------------------
/Art/Server.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujuer/Blink/1df33b2da92160b842faade83d4841a948788876/Art/Server.png
--------------------------------------------------------------------------------
/Art/Src/Blink.bmpr:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujuer/Blink/1df33b2da92160b842faade83d4841a948788876/Art/Src/Blink.bmpr
--------------------------------------------------------------------------------
/Art/Src/Logo.ai:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujuer/Blink/1df33b2da92160b842faade83d4841a948788876/Art/Src/Logo.ai
--------------------------------------------------------------------------------
/C Sharp/Blink/.gitignore:
--------------------------------------------------------------------------------
1 | bin/
2 | obj/
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.31101.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Blink", "Blink\Blink.csproj", "{30F08385-9963-42E9-9A18-7CD707336E28}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server", "Server\Server.csproj", "{CA1D566E-7EE6-41A8-B4D0-F38936E44F14}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client", "Client\Client.csproj", "{265A5FC4-7A76-42A0-A1C7-2F329C419907}"
11 | EndProject
12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlinkTest", "BlinkTest\BlinkTest.csproj", "{7A70E662-AC13-4D05-9180-668D87ADBA2D}"
13 | EndProject
14 | Global
15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
16 | Debug|Any CPU = Debug|Any CPU
17 | Release|Any CPU = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {30F08385-9963-42E9-9A18-7CD707336E28}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {30F08385-9963-42E9-9A18-7CD707336E28}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {30F08385-9963-42E9-9A18-7CD707336E28}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {30F08385-9963-42E9-9A18-7CD707336E28}.Release|Any CPU.Build.0 = Release|Any CPU
24 | {CA1D566E-7EE6-41A8-B4D0-F38936E44F14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25 | {CA1D566E-7EE6-41A8-B4D0-F38936E44F14}.Debug|Any CPU.Build.0 = Debug|Any CPU
26 | {CA1D566E-7EE6-41A8-B4D0-F38936E44F14}.Release|Any CPU.ActiveCfg = Release|Any CPU
27 | {CA1D566E-7EE6-41A8-B4D0-F38936E44F14}.Release|Any CPU.Build.0 = Release|Any CPU
28 | {265A5FC4-7A76-42A0-A1C7-2F329C419907}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29 | {265A5FC4-7A76-42A0-A1C7-2F329C419907}.Debug|Any CPU.Build.0 = Debug|Any CPU
30 | {265A5FC4-7A76-42A0-A1C7-2F329C419907}.Release|Any CPU.ActiveCfg = Release|Any CPU
31 | {265A5FC4-7A76-42A0-A1C7-2F329C419907}.Release|Any CPU.Build.0 = Release|Any CPU
32 | {7A70E662-AC13-4D05-9180-668D87ADBA2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33 | {7A70E662-AC13-4D05-9180-668D87ADBA2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
34 | {7A70E662-AC13-4D05-9180-668D87ADBA2D}.Release|Any CPU.ActiveCfg = Release|Any CPU
35 | {7A70E662-AC13-4D05-9180-668D87ADBA2D}.Release|Any CPU.Build.0 = Release|Any CPU
36 | EndGlobalSection
37 | GlobalSection(SolutionProperties) = preSolution
38 | HideSolutionNode = FALSE
39 | EndGlobalSection
40 | EndGlobal
41 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink.v12.suo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujuer/Blink/1df33b2da92160b842faade83d4841a948788876/C Sharp/Blink/Blink.v12.suo
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Async/AsyncAbsDispatcher.cs:
--------------------------------------------------------------------------------
1 | using System.Net.Sockets;
2 |
3 | namespace Net.Qiujuer.Blink.Async
4 | {
5 | public class AsyncAbsDispatcher : SocketAsyncEventArgs
6 | {
7 | protected const int HeadSize = 11;
8 |
9 | protected readonly float mProgressPrecision;
10 |
11 | protected volatile bool mDisposed = false;
12 |
13 | protected float mProgress = 0;
14 |
15 | protected bool mStatus = true;
16 |
17 |
18 | public AsyncAbsDispatcher(float progressPrecision)
19 | {
20 | mProgressPrecision = progressPrecision;
21 | }
22 |
23 |
24 | protected bool IsNotifyProgress(float newProgress)
25 | {
26 | if (newProgress == 0 ||
27 | newProgress == 1 ||
28 | (newProgress - mProgress) > mProgressPrecision)
29 | {
30 | mProgress = newProgress;
31 | return true;
32 | }
33 | else
34 | {
35 | return false;
36 | }
37 | }
38 |
39 | protected bool IsDisposed()
40 | {
41 | if (mDisposed)
42 | return true;
43 | else
44 | {
45 | mDisposed = true;
46 | return false;
47 | }
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Async/AsyncSocketAdapter.cs:
--------------------------------------------------------------------------------
1 | using Net.Qiujuer.Blink.Core;
2 | using System;
3 | using System.Net.Sockets;
4 |
5 | namespace Net.Qiujuer.Blink.Async
6 | {
7 | public class AsyncSocketAdapter : Sender, Receiver
8 | {
9 | private int mBufferSize;
10 | private Socket mSocket;
11 |
12 | public AsyncSocketAdapter(Socket socket, int bufferSize)
13 | {
14 | mSocket = socket;
15 | mSocket.ReceiveBufferSize = bufferSize;
16 | mSocket.SendBufferSize = bufferSize;
17 | mBufferSize = bufferSize;
18 | }
19 |
20 | public bool ReceiveAsync(SocketAsyncEventArgs e)
21 | {
22 | Socket socket = mSocket;
23 | if (socket != null)
24 | return mSocket.ReceiveAsync(e);
25 | else
26 | return false;
27 | }
28 |
29 | public bool SendAsync(SocketAsyncEventArgs e)
30 | {
31 | Socket socket = mSocket;
32 | if (socket != null)
33 | return mSocket.SendAsync(e);
34 | else
35 | return false;
36 | }
37 |
38 | public int GetBufferSize()
39 | {
40 | return mBufferSize;
41 | }
42 |
43 | public void Dispose()
44 | {
45 | Socket socket = mSocket;
46 | mSocket = null;
47 |
48 | if (socket != null)
49 | {
50 | try
51 | {
52 | socket.Shutdown(SocketShutdown.Both);
53 | socket.Dispose();
54 | socket.Close();
55 | }
56 | catch (Exception e)
57 | {
58 | Console.WriteLine(e.ToString());
59 | }
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Async/SocketAsyncEventArgsPool.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Net.Sockets;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace Net.Qiujuer.Blink.Async
9 | {
10 | ///
11 | /// Represents a collection of reusable SocketAsyncEventArgs objects.
12 | ///
13 | public class SocketAsyncEventArgsPool
14 | {
15 | Stack mPool;
16 |
17 | // Initializes the object pool to the specified size
18 | //
19 | // The "capacity" parameter is the maximum number of
20 | // SocketAsyncEventArgs objects the pool can hold
21 | public SocketAsyncEventArgsPool(int capacity)
22 | {
23 | mPool = new Stack(capacity);
24 | }
25 |
26 | // Add a SocketAsyncEventArg instance to the pool
27 | //
28 | //The "item" parameter is the SocketAsyncEventArgs instance
29 | // to add to the pool
30 | public void Push(SocketAsyncEventArgs item)
31 | {
32 | if (item == null) { throw new ArgumentNullException("Items added to a SocketAsyncEventArgsPool cannot be null"); }
33 | lock (mPool)
34 | {
35 | mPool.Push(item);
36 | }
37 | }
38 |
39 | // Removes a SocketAsyncEventArgs instance from the pool
40 | // and returns the object removed from the pool
41 | public SocketAsyncEventArgs Pop()
42 | {
43 | lock (mPool)
44 | {
45 | if (mPool.Count > 0)
46 | {
47 | return mPool.Pop();
48 | }
49 | else
50 | {
51 | return new SocketAsyncEventArgs();
52 | }
53 | }
54 | }
55 |
56 | // The number of SocketAsyncEventArgs instances in the pool
57 | public int Count
58 | {
59 | get { return mPool.Count; }
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Blink_Key.pfx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujuer/Blink/1df33b2da92160b842faade83d4841a948788876/C Sharp/Blink/Blink/Blink_Key.pfx
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Box/BaseReceivePacket.cs:
--------------------------------------------------------------------------------
1 | using Net.Qiujuer.Blink.Core;
2 | using System;
3 | using System.IO;
4 |
5 | namespace Net.Qiujuer.Blink.Box
6 | {
7 | public abstract class BaseReceivePacket : ReceivePacket
8 | {
9 | protected Stream mStream;
10 | protected T mEntity;
11 |
12 | public BaseReceivePacket(long id, byte type, long len)
13 | : base(id, type, len)
14 | {
15 | }
16 |
17 | public T GetEntity()
18 | {
19 | return mEntity;
20 | }
21 |
22 | internal override void Write(byte[] buffer, int offset, int count)
23 | {
24 | Stream stream = mStream;
25 | if (stream != null)
26 | {
27 | try
28 | {
29 | stream.Write(buffer, offset, count);
30 | stream.Flush();
31 | }
32 | catch (Exception) { }
33 | }
34 | }
35 |
36 | protected void CloseStream()
37 | {
38 | Stream stream = mStream;
39 | mStream = null;
40 | if (stream != null)
41 | {
42 | try
43 | {
44 | stream.Flush();
45 | stream.Dispose();
46 | stream.Close();
47 | }
48 | catch (Exception) { }
49 | }
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Box/BaseSendPacket.cs:
--------------------------------------------------------------------------------
1 | using Net.Qiujuer.Blink.Core;
2 | using Net.Qiujuer.Blink.Listener;
3 | using System;
4 | using System.IO;
5 |
6 | namespace Net.Qiujuer.Blink.Box
7 | {
8 | public abstract class BaseSendPacket : SendPacket
9 | {
10 | protected T mEntity;
11 | protected Stream mStream;
12 |
13 | public BaseSendPacket(T entity, byte type, SendListener listener)
14 | : base(type, listener)
15 | {
16 | mEntity = entity;
17 | }
18 |
19 | public T GetEntity()
20 | {
21 | return mEntity;
22 | }
23 |
24 | internal override int Read(byte[] buffer, int offset, int count)
25 | {
26 | Stream stream = mStream;
27 | if (stream == null)
28 | return -1;
29 | try
30 | {
31 | return stream.Read(buffer, offset, count);
32 | }
33 | catch (Exception)
34 | {
35 | return -1;
36 | }
37 | }
38 |
39 | protected void CloseStream()
40 | {
41 | Stream stream = mStream;
42 | mStream = null;
43 | if (stream != null)
44 | {
45 | try
46 | {
47 | stream.Dispose();
48 | stream.Close();
49 | }
50 | catch (Exception) { }
51 | }
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Box/ByteReceivePacket.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace Net.Qiujuer.Blink.Box
5 | {
6 | public class ByteReceivePacket : BaseReceivePacket
7 | {
8 | public ByteReceivePacket(long id, byte type, long len)
9 | : base(id, type, len)
10 | {
11 | }
12 |
13 | internal override bool StartPacket()
14 | {
15 | try
16 | {
17 | mStream = new MemoryStream((int)GetLength());
18 | return true;
19 | }
20 | catch (Exception)
21 | {
22 | return false;
23 | }
24 | }
25 |
26 | internal override void EndPacket()
27 | {
28 | if (mStream != null)
29 | {
30 | byte[] bytes = new byte[mStream.Length];
31 | mStream.Seek(0, SeekOrigin.Begin);
32 | mStream.Read(bytes, 0, bytes.Length);
33 | mEntity = bytes;
34 |
35 | CloseStream();
36 | }
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Box/ByteSendPacket.cs:
--------------------------------------------------------------------------------
1 | using Net.Qiujuer.Blink.Listener;
2 | using System;
3 | using System.IO;
4 |
5 | namespace Net.Qiujuer.Blink.Box
6 | {
7 | public class ByteSendPacket : BaseSendPacket
8 | {
9 | public ByteSendPacket(byte[] entity)
10 | : this(entity, null)
11 | {
12 | }
13 |
14 | public ByteSendPacket(byte[] entity, SendListener listener) :
15 | base(entity, PacketType.BYTES, listener)
16 | {
17 | mLength = mEntity.Length;
18 | }
19 |
20 | internal override bool StartPacket()
21 | {
22 | try
23 | {
24 | mStream = new MemoryStream(mEntity);
25 | return true;
26 | }
27 | catch (ArgumentOutOfRangeException)
28 | {
29 | return false;
30 | }
31 | }
32 |
33 | internal override void EndPacket()
34 | {
35 | CloseStream();
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Box/FileReceivePacket.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Security.Cryptography;
4 | using System.Text;
5 |
6 | namespace Net.Qiujuer.Blink.Box
7 | {
8 | public class FileReceivePacket : BaseReceivePacket
9 | {
10 | private string mFileName;
11 | private HashAlgorithm mHashAlgorithm = null;
12 |
13 | public FileReceivePacket(long id, byte type, long len, String path)
14 | : base(id, type, len)
15 | {
16 | mEntity = new FileInfo(path);
17 | }
18 |
19 | internal override bool StartPacket()
20 | {
21 | try
22 | {
23 | mStream = mEntity.OpenWrite();
24 | mHashAlgorithm = new MD5CryptoServiceProvider();
25 | return true;
26 | }
27 | catch (Exception)
28 | {
29 | return false;
30 | }
31 | }
32 |
33 | internal override void EndPacket()
34 | {
35 | CloseStream();
36 |
37 | // Set Name
38 | string fileName = mFileName;
39 | mFileName = null;
40 | if (fileName != null)
41 | {
42 | try
43 | {
44 | mEntity.MoveTo(Path.Combine(mEntity.DirectoryName, fileName));
45 | }
46 | catch (Exception) { }
47 | }
48 |
49 | // Hash
50 | HashAlgorithm hash = mHashAlgorithm;
51 | mHashAlgorithm = null;
52 | if (hash != null)
53 | {
54 | hash.TransformFinalBlock(new byte[0], 0, 0);
55 | SetHash(BitConverter.ToString(hash.Hash).Replace("-", ""));
56 | hash.Clear();
57 | hash.Dispose();
58 | }
59 | }
60 |
61 | internal override void Write(byte[] buffer, int offset, int count)
62 | {
63 | base.Write(buffer, offset, count);
64 |
65 | // Hash
66 | HashAlgorithm hash = mHashAlgorithm;
67 | if (hash != null)
68 | hash.TransformBlock(buffer, offset, count, null, 0);
69 |
70 | }
71 |
72 | internal override void WriteInfo(byte[] buffer, int offset, int count)
73 | {
74 | try
75 | {
76 | mFileName = Encoding.UTF8.GetString(buffer, offset, count);
77 | }
78 | catch (Exception) { }
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Box/FileSendPacket.cs:
--------------------------------------------------------------------------------
1 | using Net.Qiujuer.Blink.Listener;
2 | using System;
3 | using System.IO;
4 | using System.Text;
5 |
6 | namespace Net.Qiujuer.Blink.Box
7 | {
8 | public class FileSendPacket : BaseSendPacket
9 | {
10 | public FileSendPacket(FileInfo file)
11 | : this(file, null)
12 | {
13 | }
14 |
15 | public FileSendPacket(FileInfo entity, SendListener listener)
16 | : base(entity, PacketType.FILE, listener)
17 | {
18 | mLength = mEntity.Length;
19 | }
20 |
21 | internal override bool StartPacket()
22 | {
23 | try
24 | {
25 | mStream = mEntity.OpenRead();
26 | return true;
27 | }
28 | catch (Exception)
29 | {
30 | return false;
31 | }
32 | }
33 |
34 | internal override void EndPacket()
35 | {
36 | CloseStream();
37 | }
38 |
39 | internal override short ReadInfo(byte[] buffer, int index)
40 | {
41 | try
42 | {
43 | byte[] bytes = Encoding.UTF8.GetBytes(mEntity.Name);
44 | bytes.CopyTo(buffer, index);
45 | return Convert.ToInt16(bytes.Length);
46 | }
47 | catch (Exception)
48 | {
49 | return 0;
50 | }
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Box/StringReceivePacket.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace Net.Qiujuer.Blink.Box
5 | {
6 | public class StringReceivePacket : BaseReceivePacket
7 | {
8 | public StringReceivePacket(long id, byte type, long len)
9 | : base(id, type, len)
10 | {
11 |
12 | }
13 |
14 | internal override bool StartPacket()
15 | {
16 | try
17 | {
18 | mStream = new MemoryStream((int)GetLength());
19 | return true;
20 | }
21 | catch (Exception)
22 | {
23 | return false;
24 | }
25 | }
26 |
27 | internal override void EndPacket()
28 | {
29 | if (mStream != null)
30 | {
31 | byte[] bytes = new byte[mStream.Length];
32 | mStream.Seek(0, SeekOrigin.Begin);
33 | mStream.Read(bytes, 0, bytes.Length);
34 | mEntity = System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length);
35 |
36 | CloseStream();
37 | }
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Box/StringSendPacket.cs:
--------------------------------------------------------------------------------
1 | using Net.Qiujuer.Blink.Listener;
2 | using System;
3 | using System.Text;
4 |
5 | namespace Net.Qiujuer.Blink.Box
6 | {
7 | public class StringSendPacket : ByteSendPacket
8 | {
9 | public StringSendPacket(String entity)
10 | : this(entity, null)
11 | {
12 |
13 | }
14 |
15 | public StringSendPacket(String entity, SendListener listener)
16 | : base(Encoding.UTF8.GetBytes(entity), listener)
17 | {
18 | mType = PacketType.STRING;
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/ClassDiagram1.cd:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Core/BlinkDelivery.cs:
--------------------------------------------------------------------------------
1 | using Net.Qiujuer.Blink.Core;
2 | using Net.Qiujuer.Blink.Listener;
3 | using System;
4 |
5 | namespace Net.Qiujuer.Blink.Core
6 | {
7 | ///
8 | /// Receiver delivery interface
9 | ///
10 | public interface BlinkDelivery : IDisposable
11 | {
12 |
13 | ///
14 | /// On Socket Disconnect Post CallBack
15 | ///
16 | void PostBlinkDisconnect();
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Core/BlinkPacket.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Net.Qiujuer.Blink.Core
3 | {
4 | ///
5 | /// Blink Data Packet
6 | ///
7 | public abstract class BlinkPacket : Packet
8 | {
9 | protected byte mType;
10 | protected long mLength;
11 | private bool mSucceed;
12 |
13 | public BlinkPacket(byte type)
14 | {
15 | mType = type;
16 | }
17 |
18 | public byte GetPacketType()
19 | {
20 | return mType;
21 | }
22 |
23 | public long GetLength()
24 | {
25 | return mLength;
26 | }
27 |
28 | public void SetSuccess(bool isSuccess)
29 | {
30 | this.mSucceed = isSuccess;
31 | }
32 |
33 | public bool IsSucceed()
34 | {
35 | return mSucceed;
36 | }
37 |
38 | ///
39 | /// On Send or Receive start call this
40 | ///
41 | /// Init status
42 | internal abstract bool StartPacket();
43 |
44 | ///
45 | /// On Send or Receive end call this
46 | ///
47 | internal abstract void EndPacket();
48 |
49 | ///
50 | /// Packet Type
51 | ///
52 | public static class PacketType
53 | {
54 | public const byte STRING = 1;
55 | public const byte BYTES = 2;
56 | public const byte FILE = 3;
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Core/BlinkParser.cs:
--------------------------------------------------------------------------------
1 | using Net.Qiujuer.Blink.Box;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace Net.Qiujuer.Blink.Core
10 | {
11 | ///
12 | /// Blink parse interface
13 | ///
14 | public interface BlinkParser
15 | {
16 | ///
17 | /// Parse receiver receive data
18 | ///
19 | /// Data type
20 | /// Data Len
21 | /// ReceivePacket
22 | ReceivePacket ParseReceive(byte type, long len);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Core/Packet.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Net.Qiujuer.Blink.Core
3 | {
4 | ///
5 | /// Bink Packet Interface
6 | ///
7 | public interface Packet
8 | {
9 | ///
10 | /// Get packet type
11 | ///
12 | /// Type
13 | byte GetPacketType();
14 |
15 | ///
16 | /// Get packet length
17 | ///
18 | /// Size
19 | long GetLength();
20 |
21 | ///
22 | /// Set packet send or receive status
23 | ///
24 | /// Status
25 | void SetSuccess(bool isSuccess);
26 |
27 | ///
28 | /// Get the packet is succeed
29 | ///
30 | /// Status
31 | bool IsSucceed();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Core/ReceiveDelivery.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Net.Qiujuer.Blink.Core
8 | {
9 | public interface ReceiveDelivery
10 | {
11 | ///
12 | /// Parses a start response from the receiver.
13 | ///
14 | ///
15 | void PostReceiveStart(ReceivePacket entity);
16 |
17 | ///
18 | /// Parses a end response from the receiver.
19 | ///
20 | /// ReceivePacket
21 | /// isSuccess
22 | void PostReceiveEnd(ReceivePacket entity, bool isSuccess);
23 |
24 | ///
25 | /// Parses a progress response from the receiver.
26 | ///
27 | /// ReceivePacket
28 | /// Receive progress
29 | void PostReceiveProgress(ReceivePacket entity, float progress);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Core/ReceivePacket.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Net.Qiujuer.Blink.Core
4 | {
5 | ///
6 | /// Receive Packet
7 | ///
8 | public abstract class ReceivePacket : BlinkPacket
9 | {
10 | private readonly long mId;
11 | private String mHash;
12 |
13 | public ReceivePacket(long id, byte type, long len)
14 | : base(type)
15 | {
16 | mId = id;
17 | mLength = len;
18 | }
19 |
20 | public long GetId()
21 | {
22 | return mId;
23 | }
24 |
25 | ///
26 | /// Set Packet Hash Code
27 | ///
28 | /// HashCode
29 | public void SetHash(String hashCode)
30 | {
31 | mHash = hashCode;
32 | }
33 |
34 | ///
35 | /// Get Packet Hash Code
36 | ///
37 | /// HashCode
38 | public String GetHash()
39 | {
40 | return mHash;
41 | }
42 |
43 | ///
44 | /// On Receiver receive some info buffer call this
45 | ///
46 | /// Info data
47 | /// Buffer offset
48 | /// Buffer Count
49 | internal virtual void WriteInfo(byte[] buffer, int offset, int count) { }
50 |
51 | ///
52 | /// Receiver write buffer
53 | ///
54 | /// Buffer
55 | /// Buffer offset
56 | /// Buffer Count
57 | internal abstract void Write(byte[] buffer, int offset, int count);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Core/Receiver.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Net.Sockets;
3 | namespace Net.Qiujuer.Blink.Core
4 | {
5 | /**
6 | * Receive entity interface
7 | */
8 | public interface Receiver : IDisposable
9 | {
10 | ///
11 | /// Get receive buffer size
12 | ///
13 | /// Buffer Size
14 | int GetBufferSize();
15 |
16 | ///
17 | /// Async receive some data to buffer
18 | ///
19 | /// SocketAsyncEventArgs
20 | /// Status
21 | bool ReceiveAsync(SocketAsyncEventArgs e);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Core/Resource.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace Net.Qiujuer.Blink.Core
9 | {
10 | ///
11 | /// Blink Files Resource
12 | ///
13 | public interface Resource
14 | {
15 | ///
16 | /// Create a file from resource.
17 | ///
18 | /// Packet Id
19 | /// File Path
20 | string Create(long id);
21 |
22 | ///
23 | /// Empties the resource by oneself
24 | ///
25 | void Clear();
26 |
27 | ///
28 | /// Empties the resource by the path
29 | ///
30 | void ClearAll();
31 |
32 | ///
33 | /// Get The Mark
34 | ///
35 | /// Receive Mark
36 | string GetMark();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Core/SendDelivery.cs:
--------------------------------------------------------------------------------
1 | using Net.Qiujuer.Blink.Core;
2 | using System;
3 | namespace Net.Qiujuer.Blink.Core
4 | {
5 | ///
6 | /// Send delivery interface
7 | ///
8 | public interface SendDelivery : IDisposable
9 | {
10 | ///
11 | /// Parses a progress response from the sender.
12 | ///
13 | /// SendPacket
14 | /// Send progress
15 | void PostSendProgress(SendPacket entity, float progress);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Core/SendPacket.cs:
--------------------------------------------------------------------------------
1 | using Net.Qiujuer.Blink.Listener;
2 | using System;
3 | using System.Collections.Concurrent;
4 | using System.Collections.Generic;
5 | using System.IO;
6 | using System.Linq;
7 | using System.Net.Sockets;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 |
11 | namespace Net.Qiujuer.Blink.Core
12 | {
13 | public abstract class SendPacket : BlinkPacket
14 | {
15 | public SendListener Listener { get; private set; }
16 | private bool mCanceled;
17 | private BlinkConn mBlinkConn;
18 |
19 | public SendPacket(byte type, SendListener listener)
20 | : base(type)
21 | {
22 | Listener = listener;
23 | }
24 |
25 | ///
26 | /// Cancel the packet to send
27 | /// If the packet on sending you can't cancel it
28 | /// But you can cancel sending notify callback
29 | ///
30 | public void Cancel()
31 | {
32 | mCanceled = true;
33 | if (mBlinkConn != null)
34 | {
35 | mBlinkConn.Cancel(this);
36 | mBlinkConn = null;
37 | }
38 | }
39 |
40 | ///
41 | /// Get the packet iscanceled
42 | ///
43 | /// Is Canceled
44 | public bool IsCanceled()
45 | {
46 | return mCanceled;
47 | }
48 |
49 | ///
50 | /// Set The BlinkConn to Cancel from queue
51 | ///
52 | /// BlinkConn
53 | /// SendPacket
54 | public SendPacket SetBlinkConn(BlinkConn blinkConn)
55 | {
56 | mBlinkConn = blinkConn;
57 | return this;
58 | }
59 |
60 | ///
61 | /// On Sender send the packet call this to send packet info
62 | /// The bytes in 0~32767 size
63 | ///
64 | /// Send buffer
65 | /// Buffer start index
66 | /// Read to buffer count
67 | internal virtual short ReadInfo(byte[] buffer, int index)
68 | {
69 | return 0;
70 | }
71 |
72 | ///
73 | /// Sender read some data to send
74 | ///
75 | /// Buffer
76 | /// Buffer offset
77 | /// Buffer count
78 | /// Read to buffer count
79 | internal abstract int Read(byte[] buffer, int offset, int count);
80 |
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Core/Sender.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Net.Sockets;
3 |
4 | namespace Net.Qiujuer.Blink.Core
5 | {
6 | public interface Sender : IDisposable
7 | {
8 | ///
9 | /// Get socket send buffer size
10 | ///
11 | /// Buffer Size
12 | int GetBufferSize();
13 |
14 | ///
15 | /// Async send some byte
16 | ///
17 | /// SocketAsyncEventArgs
18 | /// Status
19 | bool SendAsync(SocketAsyncEventArgs e);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Kit/BlinkLog.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading;
6 | using System.Threading.Tasks;
7 |
8 | namespace Net.Qiujuer.Blink.Kit
9 | {
10 | /**
11 | * Logging helper class.
12 | */
13 | public static class BlinkLog
14 | {
15 | public static bool DEBUG = true;
16 |
17 | public static void setDebug(bool debug)
18 | {
19 | DEBUG = debug;
20 | }
21 |
22 | public static void I(String str)
23 | {
24 | if (DEBUG)
25 | {
26 | Console.WriteLine("INFO:" + str);
27 | }
28 | }
29 |
30 | public static void V(String str)
31 | {
32 | if (DEBUG)
33 | {
34 | Console.ForegroundColor = ConsoleColor.Blue;
35 | Console.WriteLine("VERBOSE:" + str);
36 | Console.ResetColor();
37 | }
38 | }
39 |
40 | public static void W(String str)
41 | {
42 | if (DEBUG)
43 | {
44 | Console.ForegroundColor = ConsoleColor.Yellow;
45 | Console.WriteLine("WARN:" + str);
46 | Console.ResetColor();
47 | }
48 | }
49 |
50 | public static void E(String str)
51 | {
52 | if (DEBUG)
53 | {
54 | Console.ForegroundColor = ConsoleColor.Red;
55 | Console.WriteLine("ERROR:" + str);
56 | Console.ResetColor();
57 | }
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Kit/BlinkParserImpl.cs:
--------------------------------------------------------------------------------
1 | using Net.Qiujuer.Blink.Box;
2 | using Net.Qiujuer.Blink.Core;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace Net.Qiujuer.Blink.Kit
10 | {
11 |
12 | public class BlinkParserImpl : BlinkParser
13 | {
14 | private long mId = 0;
15 | protected Resource mResource;
16 |
17 | public BlinkParserImpl(Resource resource)
18 | {
19 | mResource = resource;
20 | }
21 |
22 | public ReceivePacket ParseReceive(byte type, long len)
23 | {
24 | long id = ++mId;
25 | ReceivePacket packet = null;
26 | switch (type)
27 | {
28 | case BlinkPacket.PacketType.STRING:
29 | packet = new StringReceivePacket(id, type, len);
30 | break;
31 | case BlinkPacket.PacketType.BYTES:
32 | packet = new ByteReceivePacket(id, type, len); ;
33 | break;
34 | case BlinkPacket.PacketType.FILE:
35 | String file = mResource.Create(id);
36 | if (file != null)
37 | packet = new FileReceivePacket(id, type, len, file);
38 | break;
39 | }
40 | return packet;
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Kit/Runnable.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Net.Qiujuer.Blink.Kit
3 | {
4 | ///
5 | /// One Runnable Interface
6 | ///
7 | public interface Runnable
8 | {
9 | ///
10 | /// Doing something
11 | ///
12 | void Run();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Listener/BlinkListener.cs:
--------------------------------------------------------------------------------
1 | using Net.Qiujuer.Blink.Core;
2 | using System.Net.Sockets;
3 | namespace Net.Qiujuer.Blink.Listener
4 | {
5 | ///
6 | /// Blink notify listener
7 | ///
8 | public interface BlinkListener
9 | {
10 | ///
11 | /// On Receive or Sender error by socket err call this
12 | ///
13 | void OnBlinkDisconnect();
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Listener/ReceiveListener.cs:
--------------------------------------------------------------------------------
1 | using Net.Qiujuer.Blink.Core;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace Net.Qiujuer.Blink.Listener
9 | {
10 | ///
11 | /// Receive notify listener
12 | ///
13 | public interface ReceiveListener
14 | {
15 | ///
16 | /// On Receiver receive new packet call this
17 | ///
18 | /// Packet Type
19 | /// Packet Id
20 | void OnReceiveStart(byte type, long id);
21 |
22 | ///
23 | /// Receiver receive packet progress
24 | ///
25 | /// ReceivePacket
26 | /// Receive Progress
27 | void OnReceiveProgress(ReceivePacket packet, float progress);
28 |
29 | ///
30 | /// On Receiver end receive packet call this
31 | ///
32 | /// ReceivePacket
33 | void OnReceiveEnd(ReceivePacket packet);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Listener/SendListener.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Net.Qiujuer.Blink.Listener
3 | {
4 | ///
5 | /// Send notify listener
6 | ///
7 | public interface SendListener
8 | {
9 | ///
10 | /// On sender send the packet call this
11 | /// On start progress == 0
12 | /// On end progress ==1
13 | ///
14 | /// Send progress (0~1)
15 | void OnSendProgress(float progress);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Blink/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的常规信息通过以下
6 | // 特性集控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("Blink")]
9 | [assembly: AssemblyDescription("Blink To AsyncSocket")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("QIUJUER")]
12 | [assembly: AssemblyProduct("Blink")]
13 | [assembly: AssemblyCopyright("Copyright © QIUJUER 2015")]
14 | [assembly: AssemblyTrademark("QIUJUER")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 使此程序集中的类型
18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | // 则将该类型上的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("19f66da5-9f23-4960-9736-31af7eb00521")]
24 |
25 | // 程序集的版本信息由下面四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/C Sharp/Blink/BlinkTest/.gitignore:
--------------------------------------------------------------------------------
1 | bin/
2 | obj/
--------------------------------------------------------------------------------
/C Sharp/Blink/BlinkTest/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/C Sharp/Blink/BlinkTest/BlinkTest.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {7A70E662-AC13-4D05-9180-668D87ADBA2D}
8 | Exe
9 | Properties
10 | BlinkTest
11 | BlinkTest
12 | v4.5
13 | 512
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 | true
25 |
26 |
27 | AnyCPU
28 | pdbonly
29 | true
30 | bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | {30f08385-9963-42e9-9a18-7cd707336e28}
54 | Blink
55 |
56 |
57 |
58 |
65 |
--------------------------------------------------------------------------------
/C Sharp/Blink/BlinkTest/Program.cs:
--------------------------------------------------------------------------------
1 | using Net.Qiujuer.Blink;
2 | using Net.Qiujuer.Blink.Core;
3 | using Net.Qiujuer.Blink.Kit;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using System.Net;
8 | using System.Net.Sockets;
9 | using System.Text;
10 | using System.Threading;
11 | using System.Threading.Tasks;
12 |
13 | namespace BlinkTest
14 | {
15 | class Program
16 | {
17 | static bool IsExit;
18 | static void Main(string[] args)
19 | {
20 | for (int i = 0; i <= 50000; i++)
21 | {
22 | BlinkLog.I("=========" + i + "==========");
23 | Thread thread = new Thread(Run);
24 | thread.Start();
25 |
26 | Thread.Sleep(500);
27 | }
28 | BlinkLog.I("=========PRESS ANY KEY TO EXIT==========");
29 | Console.ReadKey();
30 | IsExit = true;
31 | }
32 |
33 | static void Run()
34 | {
35 | Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
36 |
37 | IPAddress HostIp = IPAddress.Parse("127.0.0.1");
38 | socket.Connect(HostIp, 2626);
39 |
40 | BlinkConn conn = Blink.NewConnection(socket, 1024 * 1024, "D:/", Guid.NewGuid().ToString(), 0.001f, null, null);
41 |
42 | if (conn != null)
43 | {
44 | Console.WriteLine("Test Send String...");
45 | for (int i = 0; i <= 50; i++)
46 | {
47 | string str = "Test String:" + i;
48 | conn.Send(str);
49 | Console.WriteLine(str);
50 | Thread.Sleep(2);
51 | if (IsExit)
52 | {
53 | conn.Dispose();
54 | socket.Shutdown(SocketShutdown.Both);
55 | socket.Dispose();
56 | socket.Close();
57 | return;
58 | }
59 | }
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/C Sharp/Blink/BlinkTest/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的常规信息通过以下
6 | // 特性集控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("BlinkTest")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("BlinkTest")]
13 | [assembly: AssemblyCopyright("Copyright © 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 使此程序集中的类型
18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | // 则将该类型上的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("1bc05e11-85a5-4574-9256-2692084ebcc9")]
24 |
25 | // 程序集的版本信息由下面四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Client/.gitignore:
--------------------------------------------------------------------------------
1 | bin/
2 | obj/
--------------------------------------------------------------------------------
/C Sharp/Blink/Client/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Client/Program.cs:
--------------------------------------------------------------------------------
1 | using Net.Qiujuer.Blink;
2 | using Net.Qiujuer.Blink.Core;
3 | using Net.Qiujuer.Blink.Kit;
4 | using Net.Qiujuer.Blink.Listener;
5 | using System;
6 | using System.IO;
7 | using System.Net;
8 | using System.Net.Sockets;
9 | using System.Threading;
10 |
11 | namespace Client
12 | {
13 | class Program
14 | {
15 | static Socket mSocket;
16 | static BlinkConn mBlinkConn = null;
17 |
18 | static void Main(string[] args)
19 | {
20 | BlinkLog.I("=========PRESS ENTER IP eg(127.0.0.1)==========");
21 | string ip = Console.ReadLine();
22 |
23 | IPAddress hostIp;
24 | if (!IPAddress.TryParse(ip, out hostIp))
25 | {
26 | Console.ReadKey();
27 | return;
28 | }
29 |
30 | try
31 | {
32 | mSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
33 | mSocket.Connect(hostIp, 2626);
34 | mBlinkConn = Blink.NewConnection(mSocket, 1024 * 1024, "D:/", Guid.NewGuid().ToString(), 0.01f, null, null);
35 |
36 | }
37 | catch (Exception)
38 | {
39 | BlinkLog.I("LINK TO: " + hostIp + " ERROR.");
40 | Console.ReadKey();
41 | return;
42 | }
43 |
44 | BlinkLog.I("=========PRESS ENTER 'E' TO EXIT==========");
45 |
46 | SendWhlie();
47 |
48 |
49 | if (mBlinkConn != null)
50 | mBlinkConn.Dispose();
51 | if (mSocket != null)
52 | {
53 | mSocket.Dispose();
54 | mSocket.Close();
55 | }
56 | }
57 |
58 | static void SendWhlie()
59 | {
60 |
61 | while (true)
62 | {
63 | BlinkLog.V("===== Enter some str or drag file to send. =====");
64 |
65 | string str = Console.ReadLine();
66 | if (str == "E")
67 | return;
68 | Send(str);
69 | }
70 | }
71 |
72 | static void Send(string str)
73 | {
74 | try
75 | {
76 | FileInfo info = new FileInfo(str);
77 | if (info.Exists)
78 | {
79 | mBlinkConn.Send(info, new SendCallBack());
80 | }
81 |
82 | else
83 | {
84 | mBlinkConn.Send(str);
85 | BlinkLog.I("Send String To Server.");
86 | }
87 | }
88 | catch (Exception e)
89 | {
90 | BlinkLog.E(e.Message);
91 | }
92 | }
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Client/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的常规信息通过以下
6 | // 特性集控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("Client")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Client")]
13 | [assembly: AssemblyCopyright("Copyright © 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 使此程序集中的类型
18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | // 则将该类型上的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("8251cbb2-97d1-439c-b350-694d73995d4c")]
24 |
25 | // 程序集的版本信息由下面四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Client/SendCallBack.cs:
--------------------------------------------------------------------------------
1 | using Net.Qiujuer.Blink.Listener;
2 | using System;
3 |
4 | namespace Client
5 | {
6 | class SendCallBack : SendListener
7 | {
8 |
9 | public void OnSendProgress(float progress)
10 | {
11 | Console.WriteLine("Send->progress: " + progress);
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Server/.gitignore:
--------------------------------------------------------------------------------
1 | bin/
2 | obj/
--------------------------------------------------------------------------------
/C Sharp/Blink/Server/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Server/BlinkCallBack.cs:
--------------------------------------------------------------------------------
1 | using Net.Qiujuer.Blink;
2 | using Net.Qiujuer.Blink.Box;
3 | using Net.Qiujuer.Blink.Core;
4 | using Net.Qiujuer.Blink.Listener;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Net.Sockets;
8 |
9 | namespace Server
10 | {
11 | class BlinkCallBack : BlinkListener, ReceiveListener
12 | {
13 | static List mBlinkCallBacks = new List();
14 |
15 | public Socket SocketLink { get; set; }
16 | public BlinkConn Conn { get; set; }
17 |
18 | public BlinkCallBack(Socket socket)
19 | {
20 | SocketLink = socket;
21 | Conn = Blink.NewConnection(socket,
22 | 2 * 1024 * 1024,
23 | "D:/",
24 | Guid.NewGuid().ToString(),
25 | 0.1f,
26 | this, this);
27 |
28 | mBlinkCallBacks.Add(this);
29 | }
30 |
31 |
32 | public void OnReceiveStart(byte type, long id)
33 | {
34 | Console.WriteLine("Receive->start:" + type + " " + id);
35 | }
36 |
37 | public void OnReceiveProgress(ReceivePacket paket, float progress)
38 | {
39 | Console.WriteLine("Receive->progress:" + paket.GetPacketType() + " " + paket.GetId()
40 | + " " + paket.GetLength() + " " + progress);
41 | }
42 |
43 | public void OnReceiveEnd(ReceivePacket paket)
44 | {
45 | if (paket.GetPacketType() == BlinkPacket.PacketType.STRING)
46 | Console.WriteLine("Receive->end: String:"
47 | + paket.GetId() + " " + paket.GetLength() + " :"
48 | + ((StringReceivePacket)paket).GetEntity());
49 | else if (paket.GetPacketType() == BlinkPacket.PacketType.BYTES)
50 | Console.WriteLine("Receive->end: Bytes:"
51 | + paket.GetId() + " " + paket.GetLength() + " :"
52 | + ((ByteReceivePacket)paket).GetEntity());
53 | else
54 | Console.WriteLine("Receive->end: File:"
55 | + paket.GetId()
56 | + " "
57 | + paket.GetLength()
58 | + " "
59 | + ((FileReceivePacket)paket).GetEntity().FullName
60 | + " "
61 | + paket.GetHash());
62 | }
63 |
64 |
65 | public void OnBlinkDisconnect()
66 | {
67 | Console.WriteLine("BlinkDisconnect");
68 |
69 | this.Conn.Dispose();
70 |
71 | mBlinkCallBacks.Remove(this);
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Server/Program.cs:
--------------------------------------------------------------------------------
1 | using Net.Qiujuer.Blink;
2 | using Net.Qiujuer.Blink.Core;
3 | using Net.Qiujuer.Blink.Kit;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using System.Net;
8 | using System.Net.Sockets;
9 | using System.Text;
10 | using System.Threading;
11 | using System.Threading.Tasks;
12 |
13 | namespace Server
14 | {
15 | class Program
16 | {
17 | static Socket mServer;
18 | static Thread mThread;
19 | static bool IsExit = false;
20 |
21 | static void Main(string[] args)
22 | {
23 |
24 | mServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
25 | try
26 | {
27 | IPAddress HostIp = IPAddress.Any;
28 | IPEndPoint iep = new IPEndPoint(HostIp, 2626);
29 | BlinkLog.I("Start Server Socket...");
30 | mServer.Bind(iep);
31 | mServer.Listen(Int32.MaxValue);
32 | mThread = new Thread(Run);
33 | mThread.Start();
34 |
35 | }
36 | catch (Exception)
37 | {
38 | BlinkLog.E("Start Server Error.");
39 | }
40 |
41 |
42 | BlinkLog.I("=========PRESS ANY KEY TO EXIT==========");
43 | Console.ReadKey();
44 |
45 | IsExit = true;
46 |
47 | if (mThread != null)
48 | {
49 | mThread.Interrupt();
50 | }
51 | mServer.Dispose();
52 | mServer.Close();
53 |
54 | }
55 |
56 |
57 | static void Run()
58 | {
59 | while (!IsExit)
60 | {
61 | try
62 | {
63 | BlinkLog.I("Server Socket Accept...");
64 | Socket socket = mServer.Accept();
65 | BlinkLog.V("New Client Socket.");
66 |
67 | BlinkCallBack callback = new BlinkCallBack(socket);
68 |
69 | BlinkConn conn = callback.Conn;
70 | conn.GetResource().ClearAll();
71 |
72 | BlinkLog.V("Socket To BlinkConn OK.");
73 | }
74 | catch (Exception)
75 | {
76 | //
77 | }
78 | }
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/C Sharp/Blink/Server/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的常规信息通过以下
6 | // 特性集控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("Server")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Server")]
13 | [assembly: AssemblyCopyright("Copyright © 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 使此程序集中的类型
18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | // 则将该类型上的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("1a82b26c-528e-4ce4-8a33-9fd79c405507")]
24 |
25 | // 程序集的版本信息由下面四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/C Sharp/Sample/Client/Blink.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujuer/Blink/1df33b2da92160b842faade83d4841a948788876/C Sharp/Sample/Client/Blink.dll
--------------------------------------------------------------------------------
/C Sharp/Sample/Client/Client.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujuer/Blink/1df33b2da92160b842faade83d4841a948788876/C Sharp/Sample/Client/Client.exe
--------------------------------------------------------------------------------
/C Sharp/Sample/Server/Blink.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujuer/Blink/1df33b2da92160b842faade83d4841a948788876/C Sharp/Sample/Server/Blink.dll
--------------------------------------------------------------------------------
/C Sharp/Sample/Server/Server.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujuer/Blink/1df33b2da92160b842faade83d4841a948788876/C Sharp/Sample/Server/Server.exe
--------------------------------------------------------------------------------
/Java/Blink/.gitignore:
--------------------------------------------------------------------------------
1 | .metadata/
2 | .idea/
3 | bin
4 | *.iml
--------------------------------------------------------------------------------
/Java/Blink/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.3.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Java/Blink/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/Java/Blink/library/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Java/Blink/library/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Blink
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Java/Blink/library/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=1.7
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.source=1.7
12 |
--------------------------------------------------------------------------------
/Java/Blink/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 | sourceSets {
3 | main.java.srcDirs = ['src']
4 | main.resources.srcDirs = ['src']
5 | test.java.srcDirs = ['tests/java']
6 | test.resources.srcDirs = ['tests/resources']
7 | }
8 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/BlinkClient.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink;
21 |
22 | import net.qiujuer.blink.core.ExecutorDelivery;
23 |
24 | import java.io.IOException;
25 | import java.net.InetSocketAddress;
26 | import java.net.SocketAddress;
27 | import java.nio.channels.SocketChannel;
28 |
29 | /**
30 | * Blink Conn
31 | * This class is Blink Main class
32 | * You sen and cancel packet use this
33 | */
34 | public class BlinkClient extends BlinkConnect {
35 | private SocketAddress mAddress;
36 |
37 | public BlinkClient() {
38 | setDelivery(new ExecutorDelivery(null));
39 | }
40 |
41 | public boolean connect(String ip, int port) {
42 | return connect(new InetSocketAddress(ip, port));
43 | }
44 |
45 | public boolean connect(InetSocketAddress address) {
46 | return connect((SocketAddress) address);
47 | }
48 |
49 | public boolean connect(SocketAddress address) {
50 | mAddress = address;
51 | try {
52 | SocketChannel channel = SocketChannel.open(mAddress);
53 | boolean connected = channel.isConnected();
54 | if (connected) {
55 | channel.configureBlocking(false);
56 | start(channel);
57 | }
58 | return connected;
59 | } catch (IOException e) {
60 | e.printStackTrace();
61 | return false;
62 | }
63 | }
64 |
65 | public boolean reconnect() {
66 | if (mAddress == null)
67 | throw new NullPointerException("SocketChannel address is null, you should call connect.");
68 |
69 | dispose();
70 |
71 | return connect(mAddress);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/async/AsyncDispatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/24/2015
5 | * Changed 04/24/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.async;
21 |
22 | import net.qiujuer.blink.core.PacketFilter;
23 | import net.qiujuer.blink.kit.Disposable;
24 |
25 | import java.util.concurrent.atomic.AtomicBoolean;
26 |
27 |
28 | public abstract class AsyncDispatcher extends IoEventArgs implements Disposable {
29 | // Is Disposed
30 | protected final AtomicBoolean mDisposed = new AtomicBoolean(false);
31 | // Notify progress precision
32 | protected final float mProgressPrecision;
33 | // Notify progress
34 | protected float mProgress = 0;
35 |
36 | public AsyncDispatcher(int capacity, float progressPrecision) {
37 | super(capacity);
38 | mProgressPrecision = progressPrecision;
39 | }
40 |
41 | protected boolean isNotifyProgress(float newProgress) {
42 | if (newProgress == PacketFilter.STATUS_START) {
43 | mProgress = 0;
44 | return true;
45 | } else if (newProgress == PacketFilter.STATUS_END) {
46 | mProgress = 1;
47 | return true;
48 | } else if ((newProgress - mProgress) > mProgressPrecision) {
49 | mProgress = newProgress;
50 | return true;
51 | } else {
52 | return false;
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/box/BaseReceivePacket.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.box;
21 |
22 | import net.qiujuer.blink.core.ReceivePacket;
23 |
24 | import java.io.OutputStream;
25 |
26 | /**
27 | * The Receive base class
28 | */
29 | public abstract class BaseReceivePacket extends ReceivePacket {
30 | protected OutputStream mStream;
31 | protected T mEntity;
32 |
33 | public BaseReceivePacket(long id, byte type, long len) {
34 | super(id, type, len);
35 | }
36 |
37 | public T getEntity() {
38 | return mEntity;
39 | }
40 |
41 | @Override
42 | public void write(byte[] buffer, int offset, int count) {
43 | OutputStream stream = mStream;
44 | if (stream != null) {
45 | try {
46 | stream.write(buffer, offset, count);
47 | stream.flush();
48 | } catch (Exception e) {
49 | e.printStackTrace();
50 | }
51 | }
52 | }
53 |
54 | protected void closeStream() {
55 | OutputStream stream = mStream;
56 | mStream = null;
57 | if (stream != null) {
58 | try {
59 | stream.flush();
60 | stream.close();
61 | } catch (Exception e) {
62 | e.printStackTrace();
63 | }
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/box/BaseSendPacket.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.box;
21 |
22 | import net.qiujuer.blink.core.SendPacket;
23 | import net.qiujuer.blink.core.listener.SendListener;
24 |
25 | import java.io.InputStream;
26 |
27 | /**
28 | * The Send base class
29 | */
30 | public abstract class BaseSendPacket extends SendPacket {
31 | protected T mEntity;
32 | protected InputStream mStream;
33 |
34 | public BaseSendPacket(T entity, byte type, SendListener listener) {
35 | super(type, listener);
36 | mEntity = entity;
37 | }
38 |
39 |
40 | public T getEntity() {
41 | return mEntity;
42 | }
43 |
44 | @Override
45 | public int read(byte[] buffer, int offset, int count) {
46 | InputStream stream = mStream;
47 | if (stream == null)
48 | return -1;
49 | try {
50 | return stream.read(buffer, offset, count);
51 | } catch (Exception e) {
52 | return -1;
53 | }
54 | }
55 |
56 | protected void closeStream() {
57 | InputStream stream = mStream;
58 | mStream = null;
59 | if (stream != null) {
60 | try {
61 | stream.close();
62 | } catch (Exception e) {
63 | e.printStackTrace();
64 | }
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/box/ByteReceivePacket.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.box;
21 |
22 | import java.io.ByteArrayOutputStream;
23 |
24 | /**
25 | * Bytes receive class
26 | */
27 | public class ByteReceivePacket extends BaseReceivePacket {
28 | public ByteReceivePacket(long id, byte type, long len) {
29 | super(id, type, len);
30 | }
31 |
32 | @Override
33 | public boolean startPacket() {
34 | try {
35 | mStream = new ByteArrayOutputStream((int) getLength());
36 | return true;
37 | } catch (Exception e) {
38 | return false;
39 | }
40 | }
41 |
42 | @Override
43 | public void endPacket() {
44 | if (mStream != null) {
45 | mEntity = ((ByteArrayOutputStream) mStream).toByteArray();
46 | closeStream();
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/box/ByteSendPacket.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.box;
21 |
22 | import net.qiujuer.blink.core.PacketType;
23 | import net.qiujuer.blink.core.listener.SendListener;
24 |
25 | import java.io.ByteArrayInputStream;
26 |
27 | /**
28 | * Bytes send class
29 | */
30 | public class ByteSendPacket extends BaseSendPacket {
31 | public ByteSendPacket(byte[] entity) {
32 | this(entity, null);
33 | }
34 |
35 | public ByteSendPacket(byte[] entity, SendListener listener) {
36 | super(entity, PacketType.BYTES, listener);
37 | mLength = mEntity.length;
38 | }
39 |
40 | @Override
41 | public boolean startPacket() {
42 | try {
43 | mStream = new ByteArrayInputStream(mEntity);
44 | return true;
45 | } catch (Exception e) {
46 | return false;
47 | }
48 | }
49 |
50 | @Override
51 | public void endPacket() {
52 | closeStream();
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/box/FileSendPacket.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.box;
21 |
22 | import net.qiujuer.blink.core.PacketType;
23 | import net.qiujuer.blink.core.listener.SendListener;
24 |
25 | import java.io.File;
26 | import java.io.FileInputStream;
27 | import java.io.FileNotFoundException;
28 |
29 | /**
30 | * File send class
31 | */
32 | public class FileSendPacket extends BaseSendPacket {
33 |
34 | public FileSendPacket(File file) {
35 | this(file, null);
36 | }
37 |
38 | public FileSendPacket(File entity, SendListener listener) {
39 | super(entity, PacketType.FILE, listener);
40 | mLength = mEntity.length();
41 | }
42 |
43 | @Override
44 | public boolean startPacket() {
45 | try {
46 | mStream = new FileInputStream(mEntity);
47 | return true;
48 | } catch (FileNotFoundException e) {
49 | return false;
50 | }
51 | }
52 |
53 | @Override
54 | public void endPacket() {
55 | closeStream();
56 | }
57 |
58 | @Override
59 | public byte[] getInfo() {
60 | try {
61 | return mEntity.getName().getBytes("UTF-8");
62 | } catch (Exception e) {
63 | return null;
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/box/StringReceivePacket.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.box;
21 |
22 | import java.io.ByteArrayOutputStream;
23 | import java.io.UnsupportedEncodingException;
24 |
25 | /**
26 | * String receive class
27 | */
28 | public class StringReceivePacket extends BaseReceivePacket {
29 | public StringReceivePacket(long id, byte type, long len) {
30 | super(id, type, len);
31 | }
32 |
33 | @Override
34 | public boolean startPacket() {
35 | try {
36 | mStream = new ByteArrayOutputStream((int) getLength());
37 | return true;
38 | } catch (Exception e) {
39 | return false;
40 | }
41 | }
42 |
43 | @Override
44 | public void endPacket() {
45 | if (mStream != null) {
46 | byte[] bytes = ((ByteArrayOutputStream) mStream).toByteArray();
47 | try {
48 | mEntity = new String(bytes, 0, bytes.length, "UTF-8");
49 | } catch (UnsupportedEncodingException e) {
50 | e.printStackTrace();
51 | }
52 |
53 | closeStream();
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/box/StringSendPacket.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.box;
21 |
22 | import net.qiujuer.blink.core.PacketType;
23 | import net.qiujuer.blink.core.listener.SendListener;
24 |
25 | import java.io.UnsupportedEncodingException;
26 |
27 | /**
28 | * String send class
29 | */
30 | public class StringSendPacket extends ByteSendPacket {
31 | public StringSendPacket(String entity) throws UnsupportedEncodingException {
32 | this(entity, null);
33 | }
34 |
35 | public StringSendPacket(String entity, SendListener listener) throws UnsupportedEncodingException {
36 | super(entity.getBytes("UTF-8"), listener);
37 |
38 | mType = PacketType.STRING;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/core/BlinkParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | /**
23 | * Blink parse interface
24 | */
25 | public interface BlinkParser {
26 |
27 | /**
28 | * Parse receiver receive data
29 | *
30 | * @param type Data type
31 | * @param len Data Len
32 | * @return ReceivePacket
33 | */
34 | ReceivePacket parseReceive(byte type, long len);
35 | }
36 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/core/Packet.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/25/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | /**
23 | * Blink Data Packet
24 | */
25 | public abstract class Packet {
26 | protected byte mType;
27 | protected long mLength;
28 |
29 | public Packet(byte type) {
30 | mType = type;
31 | }
32 |
33 | public byte getPacketType() {
34 | return mType;
35 | }
36 |
37 | public long getLength() {
38 | return mLength;
39 | }
40 |
41 | /**
42 | * On Send or Receive start call this
43 | *
44 | * @return Init status
45 | */
46 | public abstract boolean startPacket();
47 |
48 | /**
49 | * On Send or Receive end call this
50 | */
51 | public abstract void endPacket();
52 | }
53 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/core/PacketFilter.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.blink.core;
2 |
3 | import net.qiujuer.blink.async.IoEventArgs;
4 |
5 | /**
6 | * Blink io filter use to packet with buffer
7 | * Format packet to IoEventArgs {@link IoEventArgs}
8 | */
9 | public abstract class PacketFilter {
10 | // Send an Receive packet head size
11 | public final static int HEAD_SIZE = 11;
12 | public final static int STATUS_NEED = -1;
13 | public final static int STATUS_START = 2;
14 | public final static int STATUS_END = 4;
15 |
16 | protected IoEventArgs mArgs;
17 |
18 | public void setEventArgs(IoEventArgs args) {
19 | mArgs = args;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/core/PacketFormatter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/25/2015
5 | * Changed 04/25/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | import net.qiujuer.blink.async.IoEventArgs;
23 |
24 | /**
25 | * SendPacket formatter
26 | * Format packet to IoEventArgs {@link IoEventArgs}
27 | */
28 | public abstract class PacketFormatter extends PacketFilter {
29 | protected SendPacket mPacket;
30 |
31 | public abstract float format();
32 |
33 | public void setPacket(SendPacket packet) {
34 | mPacket = packet;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/core/PacketParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/25/2015
5 | * Changed 04/25/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | import net.qiujuer.blink.async.IoEventArgs;
23 |
24 | /**
25 | * ReceivePacket PacketParser
26 | * Parser IoEventArgs {@link IoEventArgs} to packet
27 | */
28 | public abstract class PacketParser extends PacketFilter {
29 | protected ReceivePacket mPacket;
30 |
31 | public abstract float parse();
32 |
33 | public ReceivePacket getPacket() {
34 | return mPacket;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/core/PacketType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/25/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | /**
23 | * Blink Packet Type
24 | */
25 | public class PacketType {
26 | public final static byte STRING = 1;
27 | public final static byte BYTES = 2;
28 | public final static byte FILE = 3;
29 | }
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/core/ReceiveDispatcher.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.blink.core;
2 |
3 | import net.qiujuer.blink.kit.Disposable;
4 |
5 | /**
6 | * ReceiveDispatcher
7 | */
8 | public interface ReceiveDispatcher extends Disposable {
9 | }
10 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/core/ReceivePacket.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | /**
23 | * Receive Packet
24 | */
25 | public abstract class ReceivePacket extends Packet {
26 | private final long mId;
27 | private String mHash;
28 |
29 | public ReceivePacket(long id, byte type, long len) {
30 | super(type);
31 | mId = id;
32 | mLength = len;
33 | }
34 |
35 | public long getId() {
36 | return mId;
37 | }
38 |
39 | /**
40 | * Set Packet Hash Code
41 | *
42 | * @param hashCode HashCode
43 | */
44 | public void setHash(String hashCode) {
45 | mHash = hashCode;
46 | }
47 |
48 | /**
49 | * Get Packet Hash Code
50 | *
51 | * @return HashCode
52 | */
53 | public String getHash() {
54 | return mHash;
55 | }
56 |
57 | /**
58 | * On Receiver receive same info buffer call this
59 | *
60 | * @param bytes Info data
61 | */
62 | public void setInfo(byte[] bytes) {
63 | }
64 |
65 | /**
66 | * Receiver write buffer
67 | *
68 | * @param buffer Buffer
69 | * @param offset Buffer offset
70 | * @param count Buffer Count
71 | */
72 | public abstract void write(byte[] buffer, int offset, int count);
73 | }
74 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/core/Receiver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | import net.qiujuer.blink.async.IoEventArgs;
23 | import net.qiujuer.blink.kit.Disposable;
24 |
25 | /**
26 | * This socket receiver
27 | */
28 | public interface Receiver extends Disposable {
29 | /**
30 | * Get receive buffer size
31 | *
32 | * @return Buffer Size
33 | */
34 | int getReceiveBufferSize();
35 |
36 | /**
37 | * Async receive same data to buffer
38 | *
39 | * @param e SocketAsyncEventArgs
40 | * @return Status
41 | */
42 | boolean receiveAsync(IoEventArgs e);
43 | }
44 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/core/SendDispatcher.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.blink.core;
2 |
3 | import net.qiujuer.blink.kit.Disposable;
4 |
5 | /**
6 | * Blink send dispatcher to process packet
7 | */
8 | public interface SendDispatcher extends Disposable {
9 | void send(SendPacket packet);
10 |
11 | void cancel(SendPacket packet);
12 | }
13 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/core/Sender.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core;
21 |
22 | import net.qiujuer.blink.async.IoEventArgs;
23 | import net.qiujuer.blink.kit.Disposable;
24 |
25 | /**
26 | * This socket sender
27 | */
28 | public interface Sender extends Disposable {
29 | /**
30 | * Get socket send buffer size
31 | *
32 | * @return Buffer Size
33 | */
34 | int getSendBufferSize();
35 |
36 | /**
37 | * Async send same byte
38 | *
39 | * @param e SocketAsyncEventArgs
40 | * @return Status
41 | */
42 | boolean sendAsync(IoEventArgs e);
43 | }
44 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/core/delivery/ConnectDelivery.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core.delivery;
21 |
22 | import net.qiujuer.blink.core.Connector;
23 |
24 | /**
25 | * Blink status delivery interface
26 | */
27 | public interface ConnectDelivery {
28 | /**
29 | * On Socket Disconnect Post CallBack
30 | */
31 | void postConnectClosed(Connector connector);
32 | }
33 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/core/delivery/ReceiveDelivery.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/25/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core.delivery;
21 |
22 | import net.qiujuer.blink.core.Connector;
23 | import net.qiujuer.blink.core.ReceivePacket;
24 |
25 | /**
26 | * Receiver delivery interface
27 | */
28 | public interface ReceiveDelivery {
29 | /**
30 | * Parses a start response from the receiver.
31 | *
32 | * @param packet ReceivePacket
33 | */
34 | void postReceiveStart(Connector connector, ReceivePacket packet);
35 |
36 | /**
37 | * Parses a progress response from the receiver.
38 | *
39 | * @param packet ReceivePacket
40 | * @param progress Receive progress
41 | */
42 | void postReceiveProgress(Connector connector, ReceivePacket packet, float progress);
43 |
44 | /**
45 | * Parses a end response from the receiver.
46 | *
47 | * @param packet ReceivePacket
48 | */
49 | void postReceiveCompleted(Connector connector, ReceivePacket packet);
50 | }
51 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/core/delivery/SendDelivery.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/25/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core.delivery;
21 |
22 | import net.qiujuer.blink.core.SendPacket;
23 |
24 | /**
25 | * Send delivery interface
26 | */
27 | public interface SendDelivery {
28 |
29 | /**
30 | * Parses a start response from the receiver.
31 | *
32 | * @param packet ReceivePacket
33 | */
34 | void postSendStart(SendPacket packet);
35 |
36 | /**
37 | * Parses a progress response from the sender.
38 | *
39 | * @param packet SendPacket
40 | * @param progress Send progress
41 | */
42 | void postSendProgress(SendPacket packet, float progress);
43 |
44 | /**
45 | * Parses a end response from the receiver.
46 | *
47 | * @param packet ReceivePacket
48 | */
49 | void postSendCompleted(SendPacket packet);
50 | }
51 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/core/listener/ConnectListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/25/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core.listener;
21 |
22 | import net.qiujuer.blink.core.Connector;
23 |
24 | /**
25 | * Blink notify listener
26 | */
27 | public interface ConnectListener {
28 |
29 | /**
30 | * On Receive or Sender socket error call this
31 | *
32 | * @param connector Connector
33 | */
34 | void onConnectClosed(Connector connector);
35 | }
36 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/core/listener/ReceiveListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/25/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core.listener;
21 |
22 | import net.qiujuer.blink.core.Connector;
23 | import net.qiujuer.blink.core.ReceivePacket;
24 |
25 | /**
26 | * Receive notify listener
27 | */
28 | public interface ReceiveListener {
29 | /**
30 | * On Receiver receive new packet call this
31 | *
32 | * @param connector Connector
33 | * @param packet ReceivePacket
34 | */
35 | void onReceiveStart(Connector connector, ReceivePacket packet);
36 |
37 | /**
38 | * Receiver receive packet progress
39 | *
40 | * @param connector Connector
41 | * @param packet ReceivePacket
42 | * @param progress Receive Progress
43 | */
44 | void onReceiveProgress(Connector connector, ReceivePacket packet, float progress);
45 |
46 | /**
47 | * On Receiver end receive packet call this
48 | *
49 | * @param connector Connector
50 | * @param packet ReceivePacket
51 | */
52 | void onReceiveCompleted(Connector connector, ReceivePacket packet);
53 | }
54 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/core/listener/SendListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.core.listener;
21 |
22 | import net.qiujuer.blink.core.SendPacket;
23 |
24 | /**
25 | * Send notify listener
26 | */
27 | public interface SendListener {
28 |
29 | /**
30 | * On start send the packet call
31 | *
32 | * @param packet SendPacket
33 | */
34 | void onSendStart(SendPacket packet);
35 |
36 |
37 | /**
38 | * On the packet send progress changed call
39 | *
40 | * @param packet SendPacket
41 | * @param progress Progress (0~1)
42 | */
43 | void onSendProgress(SendPacket packet, float progress);
44 |
45 | /**
46 | * On send completed call
47 | *
48 | * @param packet SendPacket
49 | */
50 | void onSendCompleted(SendPacket packet);
51 | }
52 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/kit/BlinkParserImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.kit;
21 |
22 | import net.qiujuer.blink.box.ByteReceivePacket;
23 | import net.qiujuer.blink.box.FileReceivePacket;
24 | import net.qiujuer.blink.box.StringReceivePacket;
25 | import net.qiujuer.blink.core.BlinkParser;
26 | import net.qiujuer.blink.core.PacketType;
27 | import net.qiujuer.blink.core.ReceivePacket;
28 |
29 | import java.io.File;
30 |
31 |
32 | public class BlinkParserImpl implements BlinkParser {
33 | private long mId = 0;
34 | protected Resource mResource;
35 |
36 | public BlinkParserImpl(Resource resource) {
37 | mResource = resource;
38 | }
39 |
40 | @Override
41 | public ReceivePacket parseReceive(byte type, long len) {
42 | long id = ++mId;
43 | ReceivePacket packet = null;
44 | switch (type) {
45 | case PacketType.STRING:
46 | packet = new StringReceivePacket(id, type, len);
47 | break;
48 | case PacketType.BYTES:
49 | packet = new ByteReceivePacket(id, type, len);
50 | break;
51 | case PacketType.FILE:
52 | File file = mResource.create(id);
53 | if (file != null)
54 | packet = new FileReceivePacket(id, type, len, file);
55 | break;
56 | }
57 | return packet;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/kit/Disposable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.kit;
21 |
22 | /**
23 | * Define a way to release resources allocated.
24 | */
25 | public interface Disposable {
26 | /**
27 | * Perform related to release or reset unmanaged resources application defined tasks.
28 | */
29 | void dispose();
30 | }
31 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/kit/Resource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.kit;
21 |
22 | import java.io.File;
23 |
24 | /**
25 | * Blink Files Resource
26 | */
27 | public interface Resource {
28 | /**
29 | * Create a file from resource.
30 | *
31 | * @return New file path
32 | */
33 | File create(long id);
34 |
35 | /**
36 | * Empties the resource by oneself
37 | */
38 | void clear();
39 |
40 | /**
41 | * Empties the resource by the path
42 | */
43 | void clearAll();
44 |
45 | /**
46 | * Get the Mark
47 | *
48 | * @return Receive Mark
49 | */
50 | String getMark();
51 | }
52 |
--------------------------------------------------------------------------------
/Java/Blink/library/src/net/qiujuer/blink/kit/convert/HashConverter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/16/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.blink.kit.convert;
21 |
22 | /**
23 | * Hash Converter
24 | */
25 | public class HashConverter {
26 | private static final char HEX_DIGITS[] = {'0', '1', '2', '3', '4', '5',
27 | '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
28 |
29 | /**
30 | * Convert bytes to md5 string
31 | *
32 | * @param b bytes
33 | * @return md5
34 | */
35 | public static String toMd5(byte[] b) {
36 | StringBuilder sb = new StringBuilder(b.length * 2);
37 | for (byte a : b) {
38 | sb.append(HEX_DIGITS[(a & 0xf0) >>> 4]);
39 | sb.append(HEX_DIGITS[a & 0x0f]);
40 | }
41 | return sb.toString();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Java/Blink/sample/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Java/Blink/sample/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | BlinkSample
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Java/Blink/sample/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=1.7
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.source=1.7
12 |
--------------------------------------------------------------------------------
/Java/Blink/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 | sourceSets {
3 | main.java.srcDirs = ['src']
4 | main.resources.srcDirs = ['src']
5 | test.java.srcDirs = ['tests/java']
6 | test.resources.srcDirs = ['tests/resources']
7 | }
8 |
--------------------------------------------------------------------------------
/Java/Blink/sample/src/net/qiujuer/sample/blink/CallBack.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/19/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.sample.blink;
21 |
22 | import net.qiujuer.blink.box.ByteReceivePacket;
23 | import net.qiujuer.blink.box.FileReceivePacket;
24 | import net.qiujuer.blink.box.StringReceivePacket;
25 | import net.qiujuer.blink.core.Connector;
26 | import net.qiujuer.blink.core.PacketType;
27 | import net.qiujuer.blink.core.ReceivePacket;
28 | import net.qiujuer.blink.core.listener.ConnectListener;
29 | import net.qiujuer.blink.core.listener.ReceiveListener;
30 |
31 | import java.util.Arrays;
32 |
33 | /**
34 | * Call Back status
35 | */
36 | public class CallBack implements ReceiveListener, ConnectListener {
37 |
38 | @Override
39 | public void onReceiveStart(Connector connector, ReceivePacket packet) {
40 | System.out.println("Receive->start:" + packet.getId() + " " + packet.getPacketType());
41 | }
42 |
43 | @Override
44 | public void onReceiveProgress(Connector connector, ReceivePacket packet, float progress) {
45 | System.out.println("Receive->progress:" + progress);
46 | }
47 |
48 | @Override
49 | public void onReceiveCompleted(Connector connector, ReceivePacket packet) {
50 | if (packet.getPacketType() == PacketType.STRING)
51 | System.out.println("Receive->end: String:"
52 | + packet.getId() + " " + packet.getLength() + " :"
53 | + ((StringReceivePacket) packet).getEntity());
54 | else if (packet.getPacketType() == PacketType.BYTES)
55 | System.out.println("Receive->end: Bytes:"
56 | + packet.getId() + " " + packet.getLength() + " :"
57 | + Arrays.toString(((ByteReceivePacket) packet).getEntity()));
58 | else
59 | System.out.println("Receive->end: File:"
60 | + packet.getId()
61 | + " "
62 | + packet.getLength()
63 | + " :"
64 | + ((FileReceivePacket) packet).getEntity()
65 | .getPath() + " " + packet.getHash());
66 | }
67 |
68 | @Override
69 | public void onConnectClosed(Connector connector) {
70 | System.out.println("A BlinkDisconnect.");
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/Java/Blink/sample/src/net/qiujuer/sample/blink/Client.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.sample.blink;
2 |
3 | import net.qiujuer.blink.BlinkClient;
4 | import net.qiujuer.blink.core.SendPacket;
5 | import net.qiujuer.blink.core.listener.SendListener;
6 |
7 | import java.io.File;
8 | import java.io.IOException;
9 |
10 | /**
11 | * Blink Client
12 | */
13 | public class Client {
14 | private static void send(BlinkClient connect) {
15 | System.out.println("Client Sending...");
16 |
17 | System.out.println("Send Some String.");
18 | for (int i = 0; i <= 50; i++) {
19 | connect.send("Blink String:" + i);
20 | }
21 |
22 | System.out.println("Send Some Bytes.");
23 | connect.send(new byte[]{1, 1, 0, 0});
24 | connect.send(new byte[]{1, 1, 1, 0, 1});
25 |
26 | System.out.println("Send A File.(D:/Data.txt)");
27 | connect.send(new File("F:\\TDDOWNLOAD\\Game\\LIMBO.zip"),
28 | new SendListener() {
29 | @Override
30 | public void onSendStart(SendPacket packet) {
31 | System.out.println("Send File Start.");
32 | }
33 |
34 | @Override
35 | public void onSendProgress(SendPacket packet, float progress) {
36 | System.out.println("Send File Progress:" + progress);
37 | }
38 |
39 | @Override
40 | public void onSendCompleted(SendPacket packet) {
41 | System.out.println("Send File Completed.");
42 | }
43 | });
44 | }
45 |
46 | public static void main(String[] args) throws IOException {
47 |
48 | CallBack callBack = new CallBack();
49 |
50 | BlinkClient connect = new BlinkClient();
51 | connect.setConnectListener(callBack);
52 | connect.setReceiveListener(callBack);
53 |
54 | connect.connect("127.0.0.1", 2626);
55 |
56 | send(connect);
57 |
58 | Utils.readKey();
59 |
60 | connect.dispose();
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/Java/Blink/sample/src/net/qiujuer/sample/blink/Server.java:
--------------------------------------------------------------------------------
1 | package net.qiujuer.sample.blink;
2 |
3 | import net.qiujuer.blink.BlinkServer;
4 | import net.qiujuer.blink.core.Connector;
5 |
6 | import java.io.IOException;
7 |
8 | /**
9 | * Test Server
10 | */
11 | public class Server extends Thread {
12 | public static void main(String[] args) throws IOException {
13 | final CallBack callBack = new CallBack();
14 |
15 | BlinkServer accept = new BlinkServer(new BlinkServer.ServerListener() {
16 | @Override
17 | public void onConnectClosed(Connector connector) {
18 | System.out.println("onConnectClosed:" + connector.getId());
19 | }
20 |
21 | @Override
22 | public void onConnectCreated(Connector connector) {
23 | connector.setReceiveListener(callBack);
24 | System.out.println("onConnectCreated:" + connector.getId());
25 | }
26 | });
27 | accept.bind(2626);
28 |
29 | Utils.readKey();
30 |
31 | accept.dispose();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Java/Blink/sample/src/net/qiujuer/sample/blink/Utils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Qiujuer
3 | * WebSite http://www.qiujuer.net
4 | * Created 04/19/2015
5 | * Changed 04/19/2015
6 | * Version 1.0.0
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package net.qiujuer.sample.blink;
21 |
22 | import java.io.BufferedReader;
23 | import java.io.IOException;
24 | import java.io.InputStreamReader;
25 |
26 |
27 | public class Utils {
28 | static void readKey() {
29 | System.out.println("=========PRESS ANY KEY TO EXIT==========");
30 | try {
31 | new BufferedReader(new InputStreamReader(System.in)).readLine();
32 | } catch (IOException e) {
33 | e.printStackTrace();
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Java/Blink/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':sample'
2 | include ':library'
3 |
--------------------------------------------------------------------------------
/Java/Sample/Sample.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujuer/Blink/1df33b2da92160b842faade83d4841a948788876/Java/Sample/Sample.zip
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Blink
2 | A socket send and receive agreement framework; Easy use IO.
3 | 
4 |
5 |
6 | ## Use
7 | ### `Server`
8 | * See `Java-Test-Server`
9 | * Run `Server.main()`
10 |
11 |
12 | ### `Client`
13 | * See `Java-Test-Client` or `Android-Test`
14 | * Run `Client.main()` or `Android App`
15 |
16 |
17 | ## Art
18 | ### `Server`
19 | 
20 |
21 | ### `Client`
22 | 
23 |
24 | ## Author
25 |
26 | ```javascript
27 | var info = {
28 | nickName : "qiujuer",
29 | site : "http://www.qiujuer.net"
30 | }
31 | ```
32 |
33 |
34 | License
35 | --------
36 |
37 | Copyright 2015 Qiujuer.
38 |
39 | Licensed under the Apache License, Version 2.0 (the "License");
40 | you may not use this file except in compliance with the License.
41 | You may obtain a copy of the License at
42 |
43 | http://www.apache.org/licenses/LICENSE-2.0
44 |
45 | Unless required by applicable law or agreed to in writing, software
46 | distributed under the License is distributed on an "AS IS" BASIS,
47 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
48 | See the License for the specific language governing permissions and
49 | limitations under the License.
50 |
51 |
--------------------------------------------------------------------------------
/Release/Android/Blink.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujuer/Blink/1df33b2da92160b842faade83d4841a948788876/Release/Android/Blink.jar
--------------------------------------------------------------------------------
/Release/Android/blink.aar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujuer/Blink/1df33b2da92160b842faade83d4841a948788876/Release/Android/blink.aar
--------------------------------------------------------------------------------
/Release/C Sharp/1.0.0.0/Blink.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujuer/Blink/1df33b2da92160b842faade83d4841a948788876/Release/C Sharp/1.0.0.0/Blink.dll
--------------------------------------------------------------------------------
/Release/C Sharp/1.0.0.0/Blink.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujuer/Blink/1df33b2da92160b842faade83d4841a948788876/Release/C Sharp/1.0.0.0/Blink.pdb
--------------------------------------------------------------------------------
/Release/Java/blink.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujuer/Blink/1df33b2da92160b842faade83d4841a948788876/Release/Java/blink.jar
--------------------------------------------------------------------------------