ios - Sending data over socket in Android -


i need connect socket , send credential info in order start receiving upcoming data on receive_crisis.

i'm using library socket.io android code. it's hard debug since got no log connection, don't know why , fails. never received server since started working on android side. nsdictionary equivalent jsonobject on android? sendevent equivalent send() or emit() on android? need send json object or array? finally, how log error?

it's working on ios part i'm kinda lost..

this ios code : (i modify address safe purpose):

nsdictionary *params=@{@"user":_username,@"orgid":_organizationid}; [_socketio connecttohost:@"nodejs.myserver.com" onport:3000 ];    [_socketio sendevent:@"joinparty" withdata:params]; 

this android code :

private void connectandlisten(int username) throws exception {     socket = io.socket("nodejs.myserver.com:3000");     socket.connect();      jsonobject json = new jsonobject();     json.put("user", username);     json.put("orgid", settings.getstring("orgid", ""));      log.e(tag, json.tostring());      socket.send("joinparty",json);     socket.emit("joinparty", json);      socket.on(receive_crisis, oncrisis); } 

updated question

private void connectandlisten(int id) throws exception {     io.setdefaultsslcontext(sslcontext.getdefault());      // set default hostname     hostnameverifier hostnameverifier = new hostnameverifier() {         @override         public boolean verify(string hostname, sslsession session) {             hostnameverifier hv = httpsurlconnection.getdefaulthostnameverifier();             return true;         }     };     io.setdefaulthostnameverifier(hostnameverifier);     io.options options = new io.options();     // set option     options.sslcontext = sslcontext.getdefault();     options.hostnameverifier = hostnameverifier;     options.secure = true;     socket = io.socket("nodejs.myserver.com:3000", options);     socket.connect();     jsonobject json = new jsonobject();     json.put("user", id);     json.put("orgid", settings.getstring("orgid", ""));      map<object, object> arrays = new hashmap<>();     arrays.put("user", id);     arrays.put("orgid",settings.getstring("orgid", "") );      socket.emit("joinparty", arrays);     socket.on(receive_crisis, oncallback);     socket.on("connect_error", oncallback);     socket.on("connect", oncallback);     socket.on("object", oncallback);     socket.on("connect_timeout", oncallback); }  private emitter.listener oncallback = new emitter.listener() {     @override     public void call(object... args) {         log.e(tag, args[0]+"");     } }; 

is nsdictionary equivalent jsonobject on android?

no, it's not. nsdictionary class cluster, meaning actual implementation hidden you, api user. in fact, foundation framework choose appropriate implementation @ run time based on amount of data etc. closest java map<object, object>

is sendevent equivalent send() or emit() on android?

it emit android. from official documentation

do need send json object or array?

try sending map instead. json different thing. if server expecting data in json format, send it.

finally, how log error?

you need use combination of emitter , manager it.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -