SlideShare a Scribd company logo
Copyright © 2012 Job and Esther Technologies, Inc.
Copyright © 2012 Job and Esther Technologies, Inc.
(3) NETWORKING AND
DATA ACCESS
Copyright © 2012 Job and Esther Technologies, Inc.
NETWORK PROGRAMMING (eq.net)
Copyright © 2012 Job and Esther Technologies, Inc.
eq.net.TCPSocket
In Eqela, TCP/IP sockets are implemented through
eq.net.TCPSocket
var socket = TCPSocket.create("192.168.1.1", 80);
// read and write to the socket
socket.close();
Copyright © 2012 Job and Esther Technologies, Inc.
Domain Name System (DNS)
 There are two ways to convert a host name into an
IP address:
1.Using eq.net.DNSCache
Example:
1.Using eq.net.DNSResolver
Example:
or
var ip = DNSCache.resolve(hostname);
var ip = DNSResolver.get_ip_address(hostname);
var ip_coll = DNSResolver.get_ip_addresses(hostname);
Copyright © 2012 Job and Esther Technologies, Inc.
Sequence of connecting a client
socket via TCP/IP
● Regardless of the operating system and
programming language, the process of connecting
a TCP/IP socket is as follows:
1.Create a socket / socket object
2.Resolve the server hostname into an IP address using
DNS
3.Establish a TCP connection to the destination host /
port
4.Read & write data
Copyright © 2012 Job and Esther Technologies, Inc.
Sample socket client program
class Main : Command
{
public int main(Collection args) {
var addr = args.get_index(0) as String;
Log.message("resolve '%s' ..".printf().add(addr));
var ip = DNSCache.resolve(addr);
if(ip == null) {
Log.error("failed to resolve");
return(1);
}
Log.message("connect to '%s' ..".printf().add(ip));
var os = OutputStream.create(TCPSocket.create(ip, 80));
if(os == null) {
Log.error.("failed to connect");
return(1);
}
Log.message("sending data ..");
os.write_string("hello");
Log.message("done");
return(0);
}
}
Copyright © 2012 Job and Esther Technologies, Inc.
Threading and networking
In GUI applications, you are either not allowed, or it
is not recommended, to do networking in the same
thread as the GUI
- This would freeze the user interface -
In GUI applications, networking should generally be
done in separate threads
Copyright © 2012 Job and Esther Technologies, Inc.
Network threading in Eqela
class MyNetworkTask : Task {
public Object run(EventReceiver listener) {
var socket = TCPSocket.create(“64.79.194.207“, 80);
if(socket != null) {
return(“Connected”);
}
return(“Failed”);
}
}
class Main : AlignWidget, EventReceiver {
LabelWidget status;
public void initialize() {
base.initialize();
add(status = LabelWidget.for_string(“Ready”));
}
public void start() {
base.start();
status.set_text(“Processing ..”);
Task.execute(new MyNetworkTask(), this);
}
public void on_event(Object o) {
status.set_text(o as String);
}
}
Copyright © 2012 Job and Esther Technologies, Inc.
Android: Permissions
To use certain platform features on the Android
platform, the application must declare the
permissions it requires
Specifically, Internet access requires permissions
Permissions can be declared in the Eqela application
config file (.config)
android_manifest_permissions: android.permission.INTERNET
Copyright © 2012 Job and Esther Technologies, Inc.
Availability of TCP/IP sockets
Almost all modern operating systems / software platforms
allow the use of TCP/IP sockets ..
.. with the notable exception of the HTML5 platform
Eqela does not currently support TCP/IP sockets in HTML5
applications (only HTTP is available)
Legacy platforms (such as J2ME) may also not support TCP
sockets
To maximize compatibility, use of HTTP networking is
recommended in applications
Copyright © 2012 Job and Esther Technologies, Inc.
Sequence of establishing a TCP/IP
server socket
 Regardless of the operating system and
programming language used, the sequence is the
same:
1.Create a socket / socket object
2.Bind the socket to a specific port (choose a specific
port number)
3.Start listening for incoming connections on the
socket
4.Accept connections as they come in
Copyright © 2012 Job and Esther Technologies, Inc.
Sample server program
class Main : Command
{
public int main(Collection args) {
var s = TCPSocket.create();
if(s.listen(1503) == false) {
Log.error("Failed to listen");
return(1);
}
TCPSocket c;
Log.message("waiting on port 1503 ..");
while((c = s.accept()) != null) {
Log.message("received a connection");
Log.message("received: %s".printf().add(InputStream.create(c)
.read_all_string()));
}
return(0);
}
}
Copyright © 2012 Job and Esther Technologies, Inc.
User Datagram Protocol (UDP)
UDP socket is implemented through
eq.net.UDPSocket
var socket = UDPSocket.create();
Copyright © 2012 Job and Esther Technologies, Inc.
User Datagram Protocol (UDP)
socket.send("This is data to send".to_utf8_buffer(false), "192.168.1.1", 1503);
if(socket.bind(1503) == false) {
Log.error("Failed to bind to UDP port 1503");
}
var buf = DynamicBuffer.create(8192);
if(socket.receive(buf, 1000000) > 0) {
// data was received
}
A call to bind() can be made to choose a
specific port number. If none is bound, then a
port is chosen automatically
To send and receive data, use the send() and
receive() methods
Copyright © 2012 Job and Esther Technologies, Inc.
HTTP client
Eqela also provides an implementation of an HTTP
client, which enables Eqela applications to easily
retrieve web data over the HTTP protocol.
The HTTP API can be called either in a background
thread, or in the current thread, depending on the
requirement.
The HTTP API will receive an object of type
eq.net.HTTPRequest, and will return an object of
type eq.net.HTTPResponse.
Copyright © 2012 Job and Esther Technologies, Inc.
Uniform Resource Locator (URL)
 URL is the global address of documents and other
resources on the World Wide Web
 A URL may consist of some of the following
components:
 Scheme name, host name, port number, path, query
string and fragment identifier
The syntax is:
scheme://host:port/path?query_string#fragment_id
Copyright © 2012 Job and Esther Technologies, Inc.
Uniform Resource Locator (URL)
Uniform Resource Locator is implemented through
eq.net.URL
var url = URL.for_string(str);
Copyright © 2012 Job and Esther Technologies, Inc.
Constructing an HTTPRequest
var query = HTTPRequest.create()
.set_method("GET")
.set_url(URL.for_string("http://www.eqela.com")));
var query = HTTPRequest.GET("http://www.eqela.com");
The HTTPRequest class is very flexible, and all
aspects of the query can be configured,
including HTTP headers and cookies.
Copyright © 2012 Job and Esther Technologies, Inc.
Using the HTTPClient
Once the query is constructed, it can be executed
through eq.net.HTTPClient
// Execute the query synchronously
var response = HTTPClient.get_response(query);
// Execute the query asynchronously:
HTTPClient.query(query, listener);
// The second parameter supplies a listener object of type
// eq.api.EventReceiver that will be notified of the
// query progress and the final result.
Copyright © 2012 Job and Esther Technologies, Inc.
HTTP client listener
The listener could be implemented as follows:
class MyListener : EventReceiver
{
public void on_event(Object o) {
if(o == null) {
// request failed
}
else if(o is HTTPResponse) {
// response was received
}
}
}
Copyright © 2012 Job and Esther Technologies, Inc.
Higher level protocols
Eqela offers some convenience implementations of
higher level protocols:
eq.web.rss – RSS news aggregation
eq.web.smtp – Sending email via SMTP
Copyright © 2012 Job and Esther Technologies, Inc.
DATA ACCESS (eq.data)
Copyright © 2012 Job and Esther Technologies, Inc.
The eq.data API
The eq.data module provides an easy-to-use object
oriented database / data management API
The following are the main classes and interfaces:
Database
Table
IteratorWrapper
SqlDatabase
SqlStatement
Copyright © 2012 Job and Esther Technologies, Inc.
Local database access
// open a database, creating it if necessary
var f = File.for_native_path(“C:mydatabase.db”);
var db = SqlDatabase.for_file(f);
if(db == null) {
// db does not exist
db = SqlDatabase.create_file(f);
if(db != null) {
db.execute(db.prepare(
“CREATE TABLE test ( id INTEGER, text TEXT );”));
}
}
→ Different backend implementations per each platform. Currently all
implementations are based on Sqlite
→ Currently not available for HTML5 builds
Copyright © 2012 Job and Esther Technologies, Inc.
Databases: Convenience API
var db = new Database();
db.add_table(Table.for_name(“users”).set_index(“username”));
db.add_table(Table.for_name(“sessions”));
if(db.open(File.for_native_path(“C:mydatabase.db”)) == false)
{
// FAILED
}
foreach(PropertyObject record in db.query_all(“users”)) {
// process the record
}
→ Utilizes the SqlDatabase API for actual functionality
→ Automatically creates tables, generates queries and other SQL statements
Copyright © 2012 Job and Esther Technologies, Inc.
SqlDatabase: Other databases
A database driver for any SQL database can be
integrated by creating a new class that implements
SqlDatabase
Third party native drivers can be integrated by
embedding calls to the third party driver API
(Oracle, MS SQL, MySQL, ..)
Copyright © 2012 Job and Esther Technologies, Inc.
Connecting to databases from mobile devices: What
kind of considerations does this involve?
Copyright © 2012 Job and Esther Technologies, Inc.
Direct connectivity
“Direct connectivity” : A mobile device connects
straight to the database server, and executes SQL
instructions on it
+ A very straightforward concept
- Security concerns
- Possible connectivity issues
- Lack of database drivers for mobile devices
Copyright © 2012 Job and Esther Technologies, Inc.
Connectivity via gateway
An intermediate server / service that handles the
mobile device's requests, and communicates directly
with the database. Best implemented using HTTP
+ No need to expose database server to the Internet
+ HTTP connectivity is universal
+ No need for database drivers (HTTPClient will do)
- Must set up a gateway service
Copyright © 2012 Job and Esther Technologies, Inc.
Thank you

More Related Content

What's hot (19)

PPTX
Network programming in java - PPT
kamal kotecha
 
PDF
AllegroCache with Web Servers
webhostingguy
 
PPT
Oracle database - Get external data via HTTP, FTP and Web Services
Kim Berg Hansen
 
PDF
Arduino、Web 到 IoT
Justin Lin
 
PPTX
Scale Your Data Tier With Windows Server App Fabric
Chris Dufour
 
ODP
Application Continuity with Oracle DB 12c
Léopold Gault
 
PPTX
Taking advantage of the Amazon Web Services (AWS) Family
Ben Hall
 
PDF
Felix HTTP - Paving the road to the future
Marcel Offermans
 
PPT
Intoduction to Play Framework
Knoldus Inc.
 
PDF
Web注入+http漏洞等描述
fangjiafu
 
PPTX
Java Play Restful JPA
Faren faren
 
PDF
Introduction to rest.li
Joe Betz
 
PDF
Appium Automation with Kotlin
RapidValue
 
PPTX
Java Play RESTful ebean
Faren faren
 
PDF
Programming IoT Gateways in JavaScript with macchina.io
Günter Obiltschnig
 
PDF
Programming with ZooKeeper - A basic tutorial
Jeff Smith
 
PDF
$.get, a Prime on Data Fetching
Josh Black
 
PDF
Fifty Features of Java EE 7 in 50 Minutes
glassfish
 
PDF
Threads, Queues, and More: Async Programming in iOS
TechWell
 
Network programming in java - PPT
kamal kotecha
 
AllegroCache with Web Servers
webhostingguy
 
Oracle database - Get external data via HTTP, FTP and Web Services
Kim Berg Hansen
 
Arduino、Web 到 IoT
Justin Lin
 
Scale Your Data Tier With Windows Server App Fabric
Chris Dufour
 
Application Continuity with Oracle DB 12c
Léopold Gault
 
Taking advantage of the Amazon Web Services (AWS) Family
Ben Hall
 
Felix HTTP - Paving the road to the future
Marcel Offermans
 
Intoduction to Play Framework
Knoldus Inc.
 
Web注入+http漏洞等描述
fangjiafu
 
Java Play Restful JPA
Faren faren
 
Introduction to rest.li
Joe Betz
 
Appium Automation with Kotlin
RapidValue
 
Java Play RESTful ebean
Faren faren
 
Programming IoT Gateways in JavaScript with macchina.io
Günter Obiltschnig
 
Programming with ZooKeeper - A basic tutorial
Jeff Smith
 
$.get, a Prime on Data Fetching
Josh Black
 
Fifty Features of Java EE 7 in 50 Minutes
glassfish
 
Threads, Queues, and More: Async Programming in iOS
TechWell
 

Viewers also liked (19)

PDF
Code and Conquer with Globe Labs, October 27, 2012
jobandesther
 
PDF
Eqela Web Development with Database Connectivity
Eqela
 
PDF
Cross Platform Game Development with GDAP, December 2012
jobandesther
 
PDF
Optimized Cross Platform Development
jobandesther
 
PDF
Brochure nhif
Williab Habwe
 
ODP
Graphical User Interface Development with Eqela
jobandesther
 
PDF
Hackers vs Hackers
jobandesther
 
PDF
Waterford at bonita bay bonita springs florida real estate
Bonita Springs
 
DOCX
Handling complaints leaflet
SLCC
 
DOCX
Basın bülteni
orhanaslan95
 
PPTX
1111
James Leo
 
PDF
Dossier certificación ic
CaroHorra
 
DOCX
Φύλλο εργασίας "Άγιος Παντελεήμων"
Athena Dol.
 
PPT
Stepsstone krishu Vandalur-Flat Sales in Vandalur-Apartments sales in Vandalur
Stepsstone Promoters
 
PPTX
Alimentos nutritivos mylena
veronicagonzalesg
 
PDF
Amherstburgh News
Reading Works Detroit
 
PPT
Crowdfunding for books
My French Library - IFLA 2014
 
DOC
Red Trenes
manuelmuniz
 
Code and Conquer with Globe Labs, October 27, 2012
jobandesther
 
Eqela Web Development with Database Connectivity
Eqela
 
Cross Platform Game Development with GDAP, December 2012
jobandesther
 
Optimized Cross Platform Development
jobandesther
 
Brochure nhif
Williab Habwe
 
Graphical User Interface Development with Eqela
jobandesther
 
Hackers vs Hackers
jobandesther
 
Waterford at bonita bay bonita springs florida real estate
Bonita Springs
 
Handling complaints leaflet
SLCC
 
Basın bülteni
orhanaslan95
 
1111
James Leo
 
Dossier certificación ic
CaroHorra
 
Φύλλο εργασίας "Άγιος Παντελεήμων"
Athena Dol.
 
Stepsstone krishu Vandalur-Flat Sales in Vandalur-Apartments sales in Vandalur
Stepsstone Promoters
 
Alimentos nutritivos mylena
veronicagonzalesg
 
Amherstburgh News
Reading Works Detroit
 
Crowdfunding for books
My French Library - IFLA 2014
 
Red Trenes
manuelmuniz
 
Ad

Similar to Networking and Data Access with Eqela (20)

PDF
Unit-4 networking basics in java
Amol Gaikwad
 
PPT
Scmad Chapter09
Marcel Caraciolo
 
PPTX
Networking
Jafar Nesargi
 
PDF
28 networking
Ravindra Rathore
 
PPTX
IPT Chapter 2 Web Services and Middleware - Dr. J. VijiPriya
VijiPriya Jeyamani
 
PDF
Java Network Programming, 4th Edition.pdf
ntrgiang203
 
PPT
Networking Java Socket Programming
Mousmi Pawar
 
PPTX
Enterprise JavaScript ... what the heck?
Nedelcho Delchev
 
PPT
Md13 networking
Rakesh Madugula
 
DOC
Tutorial Solution
vikram singh
 
ODP
Introduction to Eqela development
jobandesther
 
KEY
A language for the Internet: Why JavaScript and Node.js is right for Internet...
Tom Croucher
 
PDF
Java Network Programming Third Edition 3rd Edition Elliotte Rusty Harold
dxvpbvqlbt970
 
ODP
Eqela Core API and Utilities
jobandesther
 
PPTX
Asynchronous Web Programming with HTML5 WebSockets and Java
James Falkner
 
KEY
A language for the Internet: Why JavaScript and Node.js is right for Internet...
Tom Croucher
 
PPTX
httpmodule in java script all methods.pptx
sontinenianuradha
 
PPTX
Web essentials clients, servers and communication – the internet – basic inte...
smitha273566
 
KEY
Node.js - As a networking tool
Felix Geisendörfer
 
PDF
Ajp notes-chapter-04
Ankit Dubey
 
Unit-4 networking basics in java
Amol Gaikwad
 
Scmad Chapter09
Marcel Caraciolo
 
Networking
Jafar Nesargi
 
28 networking
Ravindra Rathore
 
IPT Chapter 2 Web Services and Middleware - Dr. J. VijiPriya
VijiPriya Jeyamani
 
Java Network Programming, 4th Edition.pdf
ntrgiang203
 
Networking Java Socket Programming
Mousmi Pawar
 
Enterprise JavaScript ... what the heck?
Nedelcho Delchev
 
Md13 networking
Rakesh Madugula
 
Tutorial Solution
vikram singh
 
Introduction to Eqela development
jobandesther
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
Tom Croucher
 
Java Network Programming Third Edition 3rd Edition Elliotte Rusty Harold
dxvpbvqlbt970
 
Eqela Core API and Utilities
jobandesther
 
Asynchronous Web Programming with HTML5 WebSockets and Java
James Falkner
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
Tom Croucher
 
httpmodule in java script all methods.pptx
sontinenianuradha
 
Web essentials clients, servers and communication – the internet – basic inte...
smitha273566
 
Node.js - As a networking tool
Felix Geisendörfer
 
Ajp notes-chapter-04
Ankit Dubey
 
Ad

Recently uploaded (20)

PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Advancing WebDriver BiDi support in WebKit
Igalia
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Advancing WebDriver BiDi support in WebKit
Igalia
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Biography of Daniel Podor.pdf
Daniel Podor
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 

Networking and Data Access with Eqela

  • 1. Copyright © 2012 Job and Esther Technologies, Inc.
  • 2. Copyright © 2012 Job and Esther Technologies, Inc. (3) NETWORKING AND DATA ACCESS
  • 3. Copyright © 2012 Job and Esther Technologies, Inc. NETWORK PROGRAMMING (eq.net)
  • 4. Copyright © 2012 Job and Esther Technologies, Inc. eq.net.TCPSocket In Eqela, TCP/IP sockets are implemented through eq.net.TCPSocket var socket = TCPSocket.create("192.168.1.1", 80); // read and write to the socket socket.close();
  • 5. Copyright © 2012 Job and Esther Technologies, Inc. Domain Name System (DNS)  There are two ways to convert a host name into an IP address: 1.Using eq.net.DNSCache Example: 1.Using eq.net.DNSResolver Example: or var ip = DNSCache.resolve(hostname); var ip = DNSResolver.get_ip_address(hostname); var ip_coll = DNSResolver.get_ip_addresses(hostname);
  • 6. Copyright © 2012 Job and Esther Technologies, Inc. Sequence of connecting a client socket via TCP/IP ● Regardless of the operating system and programming language, the process of connecting a TCP/IP socket is as follows: 1.Create a socket / socket object 2.Resolve the server hostname into an IP address using DNS 3.Establish a TCP connection to the destination host / port 4.Read & write data
  • 7. Copyright © 2012 Job and Esther Technologies, Inc. Sample socket client program class Main : Command { public int main(Collection args) { var addr = args.get_index(0) as String; Log.message("resolve '%s' ..".printf().add(addr)); var ip = DNSCache.resolve(addr); if(ip == null) { Log.error("failed to resolve"); return(1); } Log.message("connect to '%s' ..".printf().add(ip)); var os = OutputStream.create(TCPSocket.create(ip, 80)); if(os == null) { Log.error.("failed to connect"); return(1); } Log.message("sending data .."); os.write_string("hello"); Log.message("done"); return(0); } }
  • 8. Copyright © 2012 Job and Esther Technologies, Inc. Threading and networking In GUI applications, you are either not allowed, or it is not recommended, to do networking in the same thread as the GUI - This would freeze the user interface - In GUI applications, networking should generally be done in separate threads
  • 9. Copyright © 2012 Job and Esther Technologies, Inc. Network threading in Eqela class MyNetworkTask : Task { public Object run(EventReceiver listener) { var socket = TCPSocket.create(“64.79.194.207“, 80); if(socket != null) { return(“Connected”); } return(“Failed”); } } class Main : AlignWidget, EventReceiver { LabelWidget status; public void initialize() { base.initialize(); add(status = LabelWidget.for_string(“Ready”)); } public void start() { base.start(); status.set_text(“Processing ..”); Task.execute(new MyNetworkTask(), this); } public void on_event(Object o) { status.set_text(o as String); } }
  • 10. Copyright © 2012 Job and Esther Technologies, Inc. Android: Permissions To use certain platform features on the Android platform, the application must declare the permissions it requires Specifically, Internet access requires permissions Permissions can be declared in the Eqela application config file (.config) android_manifest_permissions: android.permission.INTERNET
  • 11. Copyright © 2012 Job and Esther Technologies, Inc. Availability of TCP/IP sockets Almost all modern operating systems / software platforms allow the use of TCP/IP sockets .. .. with the notable exception of the HTML5 platform Eqela does not currently support TCP/IP sockets in HTML5 applications (only HTTP is available) Legacy platforms (such as J2ME) may also not support TCP sockets To maximize compatibility, use of HTTP networking is recommended in applications
  • 12. Copyright © 2012 Job and Esther Technologies, Inc. Sequence of establishing a TCP/IP server socket  Regardless of the operating system and programming language used, the sequence is the same: 1.Create a socket / socket object 2.Bind the socket to a specific port (choose a specific port number) 3.Start listening for incoming connections on the socket 4.Accept connections as they come in
  • 13. Copyright © 2012 Job and Esther Technologies, Inc. Sample server program class Main : Command { public int main(Collection args) { var s = TCPSocket.create(); if(s.listen(1503) == false) { Log.error("Failed to listen"); return(1); } TCPSocket c; Log.message("waiting on port 1503 .."); while((c = s.accept()) != null) { Log.message("received a connection"); Log.message("received: %s".printf().add(InputStream.create(c) .read_all_string())); } return(0); } }
  • 14. Copyright © 2012 Job and Esther Technologies, Inc. User Datagram Protocol (UDP) UDP socket is implemented through eq.net.UDPSocket var socket = UDPSocket.create();
  • 15. Copyright © 2012 Job and Esther Technologies, Inc. User Datagram Protocol (UDP) socket.send("This is data to send".to_utf8_buffer(false), "192.168.1.1", 1503); if(socket.bind(1503) == false) { Log.error("Failed to bind to UDP port 1503"); } var buf = DynamicBuffer.create(8192); if(socket.receive(buf, 1000000) > 0) { // data was received } A call to bind() can be made to choose a specific port number. If none is bound, then a port is chosen automatically To send and receive data, use the send() and receive() methods
  • 16. Copyright © 2012 Job and Esther Technologies, Inc. HTTP client Eqela also provides an implementation of an HTTP client, which enables Eqela applications to easily retrieve web data over the HTTP protocol. The HTTP API can be called either in a background thread, or in the current thread, depending on the requirement. The HTTP API will receive an object of type eq.net.HTTPRequest, and will return an object of type eq.net.HTTPResponse.
  • 17. Copyright © 2012 Job and Esther Technologies, Inc. Uniform Resource Locator (URL)  URL is the global address of documents and other resources on the World Wide Web  A URL may consist of some of the following components:  Scheme name, host name, port number, path, query string and fragment identifier The syntax is: scheme://host:port/path?query_string#fragment_id
  • 18. Copyright © 2012 Job and Esther Technologies, Inc. Uniform Resource Locator (URL) Uniform Resource Locator is implemented through eq.net.URL var url = URL.for_string(str);
  • 19. Copyright © 2012 Job and Esther Technologies, Inc. Constructing an HTTPRequest var query = HTTPRequest.create() .set_method("GET") .set_url(URL.for_string("http://www.eqela.com"))); var query = HTTPRequest.GET("http://www.eqela.com"); The HTTPRequest class is very flexible, and all aspects of the query can be configured, including HTTP headers and cookies.
  • 20. Copyright © 2012 Job and Esther Technologies, Inc. Using the HTTPClient Once the query is constructed, it can be executed through eq.net.HTTPClient // Execute the query synchronously var response = HTTPClient.get_response(query); // Execute the query asynchronously: HTTPClient.query(query, listener); // The second parameter supplies a listener object of type // eq.api.EventReceiver that will be notified of the // query progress and the final result.
  • 21. Copyright © 2012 Job and Esther Technologies, Inc. HTTP client listener The listener could be implemented as follows: class MyListener : EventReceiver { public void on_event(Object o) { if(o == null) { // request failed } else if(o is HTTPResponse) { // response was received } } }
  • 22. Copyright © 2012 Job and Esther Technologies, Inc. Higher level protocols Eqela offers some convenience implementations of higher level protocols: eq.web.rss – RSS news aggregation eq.web.smtp – Sending email via SMTP
  • 23. Copyright © 2012 Job and Esther Technologies, Inc. DATA ACCESS (eq.data)
  • 24. Copyright © 2012 Job and Esther Technologies, Inc. The eq.data API The eq.data module provides an easy-to-use object oriented database / data management API The following are the main classes and interfaces: Database Table IteratorWrapper SqlDatabase SqlStatement
  • 25. Copyright © 2012 Job and Esther Technologies, Inc. Local database access // open a database, creating it if necessary var f = File.for_native_path(“C:mydatabase.db”); var db = SqlDatabase.for_file(f); if(db == null) { // db does not exist db = SqlDatabase.create_file(f); if(db != null) { db.execute(db.prepare( “CREATE TABLE test ( id INTEGER, text TEXT );”)); } } → Different backend implementations per each platform. Currently all implementations are based on Sqlite → Currently not available for HTML5 builds
  • 26. Copyright © 2012 Job and Esther Technologies, Inc. Databases: Convenience API var db = new Database(); db.add_table(Table.for_name(“users”).set_index(“username”)); db.add_table(Table.for_name(“sessions”)); if(db.open(File.for_native_path(“C:mydatabase.db”)) == false) { // FAILED } foreach(PropertyObject record in db.query_all(“users”)) { // process the record } → Utilizes the SqlDatabase API for actual functionality → Automatically creates tables, generates queries and other SQL statements
  • 27. Copyright © 2012 Job and Esther Technologies, Inc. SqlDatabase: Other databases A database driver for any SQL database can be integrated by creating a new class that implements SqlDatabase Third party native drivers can be integrated by embedding calls to the third party driver API (Oracle, MS SQL, MySQL, ..)
  • 28. Copyright © 2012 Job and Esther Technologies, Inc. Connecting to databases from mobile devices: What kind of considerations does this involve?
  • 29. Copyright © 2012 Job and Esther Technologies, Inc. Direct connectivity “Direct connectivity” : A mobile device connects straight to the database server, and executes SQL instructions on it + A very straightforward concept - Security concerns - Possible connectivity issues - Lack of database drivers for mobile devices
  • 30. Copyright © 2012 Job and Esther Technologies, Inc. Connectivity via gateway An intermediate server / service that handles the mobile device's requests, and communicates directly with the database. Best implemented using HTTP + No need to expose database server to the Internet + HTTP connectivity is universal + No need for database drivers (HTTPClient will do) - Must set up a gateway service
  • 31. Copyright © 2012 Job and Esther Technologies, Inc. Thank you