android - Making chat app -
i want chat application , found code on github : https://github.com/pirngruber/androidim. , author created function send message looks this
public string sendhttprequest(string params) { url url; string result = new string(); try { url = new url(authentication_server_address); httpurlconnection connection; connection = (httpurlconnection) url.openconnection(); connection.setdooutput(true); printwriter out = new printwriter(connection.getoutputstream()); out.println(params); out.close(); bufferedreader in = new bufferedreader( new inputstreamreader( connection.getinputstream())); string inputline; while ((inputline = in.readline()) != null) { result = result.concat(inputline); } in.close(); } catch (malformedurlexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } if (result.length() == 0) { result = http_request_failed; } return result; }
where private static final string authentication_server_address = "http://192.168.0.102/android-im/index.php";
and here explained how make run https://code.google.com/archive/p/simple-android-instant-messaging-application/
so, question that: understood author sends messages server , after server sends them user. so, if pc turned off server won't work , chat won't work too, right? if yes, can explain me how chat app without server?
thank you
yes, seems requires server online @ times. that's how modern chat applications on smartphones work (telegram, whatsapp, threema, google chats...). without server rely on fact both smartphones online @ same time in order establish direct connection. huge disadvantage , works against power-saving features of mobile os. 2 parties can hardly communicate if online @ different times.
so need decide whether want peer-to-peer or server-based chat. remember in case of p2p, have figure out ip addresses of other chat clients. , you'll have use sort of server, again.
Comments
Post a Comment