-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit dc363f1
Showing
41 changed files
with
1,123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 26 | ||
defaultConfig { | ||
applicationId "com.example.kevin.websocket_stomp" | ||
minSdkVersion 15 | ||
targetSdkVersion 26 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation 'com.android.support:appcompat-v7:26.1.0' | ||
implementation 'com.android.support.constraint:constraint-layout:1.0.2' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'com.android.support.test:runner:1.0.1' | ||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' | ||
|
||
// compile "org.java-websocket:java-websocket:1.3.2" | ||
compile "org.java-websocket:Java-WebSocket:1.3.8" | ||
compile 'com.squareup.okhttp3:okhttp:3.8.0' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
26 changes: 26 additions & 0 deletions
26
app/src/androidTest/java/com/example/kevin/websocket_stomp/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.example.kevin.websocket_stomp; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() throws Exception { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.example.kevin.websocket_stomp", appContext.getPackageName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.kevin.websocket_stomp"> | ||
<uses-permission android:name="android.permission.INTERNET"/> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
105 changes: 105 additions & 0 deletions
105
app/src/main/java/com/example/kevin/websocket_stomp/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package com.example.kevin.websocket_stomp; | ||
|
||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.View; | ||
|
||
import com.example.kevin.websocket_stomp.stomp.StompCommand; | ||
import com.example.kevin.websocket_stomp.stomp.StompHeader; | ||
import com.example.kevin.websocket_stomp.stomp.StompMessage; | ||
|
||
import org.java_websocket.client.WebSocketClient; | ||
import org.java_websocket.handshake.ServerHandshake; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.ArrayList; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
private WebSocketClient mWebSocketClient; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
} | ||
|
||
/** | ||
* 1、开始建立连接 | ||
* @param view | ||
*/ | ||
public void connectStomp(View view) throws URISyntaxException { | ||
URI uri = new URI("ws://api.qiansquare.com/im-ws/469/101346jpbefgloia3232lnefhgrkbskijz/websocket"); | ||
mWebSocketClient = new WebSocketClient(uri) { | ||
@Override | ||
public void onOpen(ServerHandshake handshakedata) { | ||
Log.d("TAG","连接打开"); | ||
|
||
} | ||
|
||
@Override | ||
public void onMessage(String message) { | ||
Log.d("TAG","收到消息:"+message); | ||
|
||
} | ||
|
||
@Override | ||
public void onClose(int code, String reason, boolean remote) { | ||
Log.d("TAG","连接关闭:"+reason+"错误码:"+code); | ||
|
||
} | ||
|
||
@Override | ||
public void onError(Exception ex) { | ||
Log.d("TAG","连接出错"); | ||
|
||
} | ||
}; | ||
mWebSocketClient.connect(); | ||
|
||
} | ||
|
||
/** | ||
* 断开连接 | ||
* @param view | ||
*/ | ||
public void disconnectStomp(View view) { | ||
|
||
|
||
} | ||
|
||
/** | ||
* 2、发送COnnect命令 | ||
* @param view | ||
*/ | ||
public void sendConnect(View view) { | ||
ArrayList<StompHeader> stompHeaders = new ArrayList<>(); | ||
stompHeaders.add(new StompHeader("accept-version", "1.1,1.0")); | ||
stompHeaders.add(new StompHeader("heart-beat", "30000,30000")); | ||
//secret | ||
stompHeaders.add(new StompHeader("passcode", "dabfd6cfd8f94fd89b23eb6e2bd7d7af1521684997")); | ||
//token | ||
stompHeaders.add(new StompHeader("login", "458ea8d6138b42009e5e0619f7751b3d18038102")); | ||
StompMessage stompMessage = new StompMessage(StompCommand.CONNECT, stompHeaders, null); | ||
String compile = stompMessage.compile(); | ||
mWebSocketClient.send(compile); | ||
|
||
} | ||
|
||
|
||
|
||
/** | ||
* 3、发送心跳 | ||
* @param view | ||
*/ | ||
public void sendBeat(View view) { | ||
|
||
} | ||
/** | ||
* TODO | ||
* 发送订阅命令 | ||
*/ | ||
} |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/example/kevin/websocket_stomp/stomp/StompCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.example.kevin.websocket_stomp.stomp; | ||
|
||
/** | ||
* Created by naik on 05.05.16. | ||
*/ | ||
public class StompCommand { | ||
|
||
public static final String CONNECT = "CONNECT"; | ||
public static final String CONNECTED = "CONNECTED"; | ||
public static final String SEND = "SEND"; | ||
public static final String MESSAGE = "MESSAGE"; | ||
public static final String SUBSCRIBE = "SUBSCRIBE"; | ||
public static final String UNSUBSCRIBE = "UNSUBSCRIBE"; | ||
|
||
public static final String UNKNOWN = "UNKNOWN"; | ||
} |
31 changes: 31 additions & 0 deletions
31
app/src/main/java/com/example/kevin/websocket_stomp/stomp/StompHeader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.example.kevin.websocket_stomp.stomp; | ||
|
||
/** | ||
* Created by kevin on 2018/3/22. | ||
*/ | ||
|
||
public class StompHeader { | ||
public static final String VERSION = "version"; | ||
public static final String HEART_BEAT = "heart-beat"; | ||
public static final String DESTINATION = "destination"; | ||
public static final String CONTENT_TYPE = "content-type"; | ||
public static final String MESSAGE_ID = "message-id"; | ||
public static final String ID = "id"; | ||
public static final String ACK = "ack"; | ||
|
||
private final String mKey; | ||
private final String mValue; | ||
|
||
public StompHeader(String key, String value) { | ||
mKey = key; | ||
mValue = value; | ||
} | ||
|
||
public String getKey() { | ||
return mKey; | ||
} | ||
|
||
public String getValue() { | ||
return mValue; | ||
} | ||
} |
Oops, something went wrong.