Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Can android be an http server

808 Aufrufe

Veröffentlicht am

LT at Shibuya.apk #22
Introduction to how to make Android Device an HTTP server.

Demo app is available at my GitHub repository below.
https://github.com/chooyan-eng/AndroidHttpServerDemo

Veröffentlicht in: Software
  • Login to see the comments

Can android be an http server

  1. 1. Can Android be an HTTP Server? 2018.02.06 Tue. Tsuyoshi Chujo @ shibuya.apk # 22
  2. 2. About me Tsuyoshi Chujo ● Freelance engineer of Web services ○ Android, Web server (Servlet, Django, Ruby on Rails), etc. ● Currently, working as an Android developer in a manufacturer ● Social Accounts ○ Qiita: @chooyan-eng ○ GitHub: @chooyan-eng ○ dev.to: @chooyan ○ Twitter: @chooyan_i18n ● CodeYourRuby the device powered by Android (but NOT a Smart Phone)
  3. 3. Can Android be an HTTP Server? Ordinal architecture Client Server request response
  4. 4. Can Android be an HTTP Server? What I would like to discuss today Client Server request response
  5. 5. YES! Android CAN be an HTTP Server! ● HTTP is based on TCP ● HTTP is a protocol of “How to Control TCP” ○ See OSI or TCP/IP in detail ● All the OS (as far as I know) can use TCP. It’s the function of OS. ● Android OS also can use TCP ● Thus, Android device can be a HTTP server by extending TCP and implementing the specification on RFC 7230.
  6. 6. How to implement? ● Use java.net.ServerSocket ○ Basic class to accept requests based on TCP/IP protocol ○ InputStream and OutputStream of this class presents TCP Socket. ○ See my GitHub repository if you are interested in usage.
  7. 7. Flow Image Client Server open socket connect accept GET / HTTP/1.1CRLFUser-Agent: XXXXCRLFCookie:... parse and calculate the end of data. do something... Then, send back response.receive data and parse send data HTTP/1.1 200 OKCRLFContent-Type: text/htmlCRLF... establish connection
  8. 8. Demo if app does not work… see below :-( https://www.youtube.com/watch?v=_hZ_UsFKnIU Open the URL below with your favorite web browser :-) http://XXX.XXX.XXX.XXX:20000 https://github.com/chooyan-eng/AndroidHttpServerDemo
  9. 9. When to Use? (in my experience) ● Embedded Android (Android on devices for specific operation) ○ Send data DIRECTLY from PC to Android devices via LAN. ○ Send data with TCP connection. (Not using HTTP, but basic idea is the same as discussion here) end data and control the device response
  10. 10. Thank you!

×