android - WebSocket and Rx Java -


i'm develop android app communicates server using protocol websocket. use asyncandroid lib. websocket has listener, receive data server.

something this

private websocket.stringcallback mstringcallback = new websocket.stringcallback() {         @override         public void onstringavailable(string s) {          }     }; 

i need write api this, , want use rxjava. cannot imagine, should observable, , observer. tried observable string received server websocket listener, think bad idea. there ideas how correctly build api. thank u.

you wrap websocket new interface this:

interface rxwebsocket {     void send(byte[]); // send data     observable<string> stringobservable(); // receive string data } 

then in rxwebsocket implementation can use publishsubject internal websocket.stringcallback publish strings.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -