# AndroidWebSocket **Repository Path**: gogtz_992/AndroidWebSocket ## Basic Information - **Project Name**: AndroidWebSocket - **Description**: a simple use for websocket in android - **Primary Language**: Android - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 12 - **Created**: 2017-09-11 - **Last Updated**: 2020-12-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # AndroidWebSocket Help to use webSocket in Android based on "org.java-websocket:Java-WebSocket:1.3.4" #### dependencies Maven ```` xyz.leohan AndroidWebSocket 1.0.1 pom ```` Gradle ```` compile 'xyz.leohan:AndroidWebSocket:1.1.1-beta' ```` #### How to Use 1. write your own BroadcastReceiver extends xyz.leohan.websocketlib.WebSocketReceiver like this: ````java public class MyReceiver extends WebSocketReceiver { @Override public void onMessage(String msg) { //Here is message from webSocket //you can deal it with eventBus、RxBus、Notification and so on Log.i("webSocket", msg); } } ```` 2. write these in your AndroidManifest.xml: ```` ```` 3. call init() : ```java //do this in your BaseApplication or MainActivity //Make sure you called this only once WebSocketAndroidClient.init(this,"ws://192.168.1.108:9898"); WebSocketAndroidClient.getInstance().connect(); ```` 4. call disconnect: it will auto reconnect by error or server offline,but when you call disconnect,you need call connect again ```java WebSocketAndroidClient.getInstance().disConnect(); ``` 5. send message: ```java WebSocketAndroidClient.getInstance().sendMsg(editText.getText().toString()); ``` #### Contact me if you have any trouble in use this lib ,you can send me an e-mail :leo@leohan.xyz