SlideShare a Scribd company logo
1 of 31
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

Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPTkamal kotecha
 
AllegroCache with Web Servers
AllegroCache with Web ServersAllegroCache with Web Servers
AllegroCache with Web Serverswebhostingguy
 
Oracle database - Get external data via HTTP, FTP and Web Services
Oracle database - Get external data via HTTP, FTP and Web ServicesOracle database - Get external data via HTTP, FTP and Web Services
Oracle database - Get external data via HTTP, FTP and Web ServicesKim Berg Hansen
 
Arduino、Web 到 IoT
Arduino、Web 到 IoTArduino、Web 到 IoT
Arduino、Web 到 IoTJustin Lin
 
Scale Your Data Tier With Windows Server App Fabric
Scale Your Data Tier With Windows Server App FabricScale Your Data Tier With Windows Server App Fabric
Scale Your Data Tier With Windows Server App FabricChris Dufour
 
Application Continuity with Oracle DB 12c
Application Continuity with Oracle DB 12c Application Continuity with Oracle DB 12c
Application Continuity with Oracle DB 12c Léopold Gault
 
Taking advantage of the Amazon Web Services (AWS) Family
Taking advantage of the Amazon Web Services (AWS) FamilyTaking advantage of the Amazon Web Services (AWS) Family
Taking advantage of the Amazon Web Services (AWS) FamilyBen Hall
 
Felix HTTP - Paving the road to the future
Felix HTTP - Paving the road to the futureFelix HTTP - Paving the road to the future
Felix HTTP - Paving the road to the futureMarcel Offermans
 
Intoduction to Play Framework
Intoduction to Play FrameworkIntoduction to Play Framework
Intoduction to Play FrameworkKnoldus Inc.
 
Web注入+http漏洞等描述
Web注入+http漏洞等描述Web注入+http漏洞等描述
Web注入+http漏洞等描述fangjiafu
 
Java Play Restful JPA
Java Play Restful JPAJava Play Restful JPA
Java Play Restful JPAFaren faren
 
Introduction to rest.li
Introduction to rest.liIntroduction to rest.li
Introduction to rest.liJoe Betz
 
Appium Automation with Kotlin
Appium Automation with KotlinAppium Automation with Kotlin
Appium Automation with KotlinRapidValue
 
Java Play RESTful ebean
Java Play RESTful ebeanJava Play RESTful ebean
Java Play RESTful ebeanFaren faren
 
Programming IoT Gateways in JavaScript with macchina.io
Programming IoT Gateways in JavaScript with macchina.ioProgramming IoT Gateways in JavaScript with macchina.io
Programming IoT Gateways in JavaScript with macchina.ioGünter Obiltschnig
 
Programming with ZooKeeper - A basic tutorial
Programming with ZooKeeper - A basic tutorialProgramming with ZooKeeper - A basic tutorial
Programming with ZooKeeper - A basic tutorialJeff Smith
 
$.get, a Prime on Data Fetching
$.get, a Prime on Data Fetching$.get, a Prime on Data Fetching
$.get, a Prime on Data FetchingJosh Black
 
Fifty Features of Java EE 7 in 50 Minutes
Fifty Features of Java EE 7 in 50 MinutesFifty Features of Java EE 7 in 50 Minutes
Fifty Features of Java EE 7 in 50 Minutesglassfish
 
Threads, Queues, and More: Async Programming in iOS
Threads, Queues, and More: Async Programming in iOSThreads, Queues, and More: Async Programming in iOS
Threads, Queues, and More: Async Programming in iOSTechWell
 

What's hot (19)

Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPT
 
AllegroCache with Web Servers
AllegroCache with Web ServersAllegroCache with Web Servers
AllegroCache with Web Servers
 
Oracle database - Get external data via HTTP, FTP and Web Services
Oracle database - Get external data via HTTP, FTP and Web ServicesOracle database - Get external data via HTTP, FTP and Web Services
Oracle database - Get external data via HTTP, FTP and Web Services
 
Arduino、Web 到 IoT
Arduino、Web 到 IoTArduino、Web 到 IoT
Arduino、Web 到 IoT
 
Scale Your Data Tier With Windows Server App Fabric
Scale Your Data Tier With Windows Server App FabricScale Your Data Tier With Windows Server App Fabric
Scale Your Data Tier With Windows Server App Fabric
 
Application Continuity with Oracle DB 12c
Application Continuity with Oracle DB 12c Application Continuity with Oracle DB 12c
Application Continuity with Oracle DB 12c
 
Taking advantage of the Amazon Web Services (AWS) Family
Taking advantage of the Amazon Web Services (AWS) FamilyTaking advantage of the Amazon Web Services (AWS) Family
Taking advantage of the Amazon Web Services (AWS) Family
 
Felix HTTP - Paving the road to the future
Felix HTTP - Paving the road to the futureFelix HTTP - Paving the road to the future
Felix HTTP - Paving the road to the future
 
Intoduction to Play Framework
Intoduction to Play FrameworkIntoduction to Play Framework
Intoduction to Play Framework
 
Web注入+http漏洞等描述
Web注入+http漏洞等描述Web注入+http漏洞等描述
Web注入+http漏洞等描述
 
Java Play Restful JPA
Java Play Restful JPAJava Play Restful JPA
Java Play Restful JPA
 
Introduction to rest.li
Introduction to rest.liIntroduction to rest.li
Introduction to rest.li
 
Appium Automation with Kotlin
Appium Automation with KotlinAppium Automation with Kotlin
Appium Automation with Kotlin
 
Java Play RESTful ebean
Java Play RESTful ebeanJava Play RESTful ebean
Java Play RESTful ebean
 
Programming IoT Gateways in JavaScript with macchina.io
Programming IoT Gateways in JavaScript with macchina.ioProgramming IoT Gateways in JavaScript with macchina.io
Programming IoT Gateways in JavaScript with macchina.io
 
Programming with ZooKeeper - A basic tutorial
Programming with ZooKeeper - A basic tutorialProgramming with ZooKeeper - A basic tutorial
Programming with ZooKeeper - A basic tutorial
 
$.get, a Prime on Data Fetching
$.get, a Prime on Data Fetching$.get, a Prime on Data Fetching
$.get, a Prime on Data Fetching
 
Fifty Features of Java EE 7 in 50 Minutes
Fifty Features of Java EE 7 in 50 MinutesFifty Features of Java EE 7 in 50 Minutes
Fifty Features of Java EE 7 in 50 Minutes
 
Threads, Queues, and More: Async Programming in iOS
Threads, Queues, and More: Async Programming in iOSThreads, Queues, and More: Async Programming in iOS
Threads, Queues, and More: Async Programming in iOS
 

Viewers also liked

Code and Conquer with Globe Labs, October 27, 2012
Code and Conquer with Globe Labs, October 27, 2012Code and Conquer with Globe Labs, October 27, 2012
Code and Conquer with Globe Labs, October 27, 2012jobandesther
 
Eqela Web Development with Database Connectivity
Eqela Web Development with Database ConnectivityEqela Web Development with Database Connectivity
Eqela Web Development with Database ConnectivityEqela
 
Cross Platform Game Development with GDAP, December 2012
Cross Platform Game Development with GDAP, December 2012Cross Platform Game Development with GDAP, December 2012
Cross Platform Game Development with GDAP, December 2012jobandesther
 
Optimized Cross Platform Development
Optimized Cross Platform DevelopmentOptimized Cross Platform Development
Optimized Cross Platform Developmentjobandesther
 
Graphical User Interface Development with Eqela
Graphical User Interface Development with EqelaGraphical User Interface Development with Eqela
Graphical User Interface Development with Eqelajobandesther
 
Hackers vs Hackers
Hackers vs HackersHackers vs Hackers
Hackers vs Hackersjobandesther
 
Waterford at bonita bay bonita springs florida real estate
Waterford at bonita bay bonita springs florida real estateWaterford at bonita bay bonita springs florida real estate
Waterford at bonita bay bonita springs florida real estateBonita Springs
 
Handling complaints leaflet
Handling complaints leafletHandling complaints leaflet
Handling complaints leafletSLCC
 
Dossier certificación ic
Dossier certificación icDossier certificación ic
Dossier certificación icCaroHorra
 
Φύλλο εργασίας "Άγιος Παντελεήμων"
Φύλλο εργασίας "Άγιος Παντελεήμων"Φύλλο εργασίας "Άγιος Παντελεήμων"
Φύλλο εργασίας "Άγιος Παντελεήμων"Athena Dol.
 
Stepsstone krishu Vandalur-Flat Sales in Vandalur-Apartments sales in Vandalur
Stepsstone krishu Vandalur-Flat Sales in Vandalur-Apartments sales in VandalurStepsstone krishu Vandalur-Flat Sales in Vandalur-Apartments sales in Vandalur
Stepsstone krishu Vandalur-Flat Sales in Vandalur-Apartments sales in VandalurStepsstone Promoters
 

Viewers also liked (19)

Code and Conquer with Globe Labs, October 27, 2012
Code and Conquer with Globe Labs, October 27, 2012Code and Conquer with Globe Labs, October 27, 2012
Code and Conquer with Globe Labs, October 27, 2012
 
Eqela Web Development with Database Connectivity
Eqela Web Development with Database ConnectivityEqela Web Development with Database Connectivity
Eqela Web Development with Database Connectivity
 
Cross Platform Game Development with GDAP, December 2012
Cross Platform Game Development with GDAP, December 2012Cross Platform Game Development with GDAP, December 2012
Cross Platform Game Development with GDAP, December 2012
 
Optimized Cross Platform Development
Optimized Cross Platform DevelopmentOptimized Cross Platform Development
Optimized Cross Platform Development
 
Brochure nhif
Brochure nhifBrochure nhif
Brochure nhif
 
Graphical User Interface Development with Eqela
Graphical User Interface Development with EqelaGraphical User Interface Development with Eqela
Graphical User Interface Development with Eqela
 
Hackers vs Hackers
Hackers vs HackersHackers vs Hackers
Hackers vs Hackers
 
Waterford at bonita bay bonita springs florida real estate
Waterford at bonita bay bonita springs florida real estateWaterford at bonita bay bonita springs florida real estate
Waterford at bonita bay bonita springs florida real estate
 
Handling complaints leaflet
Handling complaints leafletHandling complaints leaflet
Handling complaints leaflet
 
Basın bülteni
Basın bülteniBasın bülteni
Basın bülteni
 
Rm 12 tarea (1)
Rm 12  tarea (1)Rm 12  tarea (1)
Rm 12 tarea (1)
 
1111
11111111
1111
 
Dossier certificación ic
Dossier certificación icDossier certificación ic
Dossier certificación ic
 
Φύλλο εργασίας "Άγιος Παντελεήμων"
Φύλλο εργασίας "Άγιος Παντελεήμων"Φύλλο εργασίας "Άγιος Παντελεήμων"
Φύλλο εργασίας "Άγιος Παντελεήμων"
 
Stepsstone krishu Vandalur-Flat Sales in Vandalur-Apartments sales in Vandalur
Stepsstone krishu Vandalur-Flat Sales in Vandalur-Apartments sales in VandalurStepsstone krishu Vandalur-Flat Sales in Vandalur-Apartments sales in Vandalur
Stepsstone krishu Vandalur-Flat Sales in Vandalur-Apartments sales in Vandalur
 
Alimentos nutritivos mylena
Alimentos nutritivos mylenaAlimentos nutritivos mylena
Alimentos nutritivos mylena
 
Amherstburgh News
Amherstburgh NewsAmherstburgh News
Amherstburgh News
 
Crowdfunding for books
Crowdfunding for booksCrowdfunding for books
Crowdfunding for books
 
Red Trenes
Red TrenesRed Trenes
Red Trenes
 

Similar to Networking and Data Access with Eqela

Socket Programming it-slideshares.blogspot.com
Socket  Programming it-slideshares.blogspot.comSocket  Programming it-slideshares.blogspot.com
Socket Programming it-slideshares.blogspot.comphanleson
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaYevgeniy Brikman
 
Advance Java-Network Programming
Advance Java-Network ProgrammingAdvance Java-Network Programming
Advance Java-Network Programmingashok hirpara
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applicationsTom Croucher
 
WebTalk - Implementing Web Services with a dedicated Java daemon
WebTalk - Implementing Web Services with a dedicated Java daemonWebTalk - Implementing Web Services with a dedicated Java daemon
WebTalk - Implementing Web Services with a dedicated Java daemonGeert Van Pamel
 
Java Socket Programming
Java Socket ProgrammingJava Socket Programming
Java Socket ProgrammingVipin Yadav
 
Mobile webapplication development
Mobile webapplication developmentMobile webapplication development
Mobile webapplication developmentGanesh Gembali
 
Socket Programming - nitish nagar
Socket Programming - nitish nagarSocket Programming - nitish nagar
Socket Programming - nitish nagarNitish Nagar
 
KSDG-iSlide App 開發心得分享
KSDG-iSlide App 開發心得分享KSDG-iSlide App 開發心得分享
KSDG-iSlide App 開發心得分享Chia Wei Tsai
 
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 202010 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020Matt Raible
 
Networking.ppt(client/server, socket) uses in program
Networking.ppt(client/server, socket) uses in programNetworking.ppt(client/server, socket) uses in program
Networking.ppt(client/server, socket) uses in programgovindjha339843
 
Networking & Socket Programming In Java
Networking & Socket Programming In JavaNetworking & Socket Programming In Java
Networking & Socket Programming In JavaAnkur Agrawal
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSocketsGonzalo Ayuso
 
GWT Web Socket and data serialization
GWT Web Socket and data serializationGWT Web Socket and data serialization
GWT Web Socket and data serializationGWTcon
 

Similar to Networking and Data Access with Eqela (20)

Socket Programming it-slideshares.blogspot.com
Socket  Programming it-slideshares.blogspot.comSocket  Programming it-slideshares.blogspot.com
Socket Programming it-slideshares.blogspot.com
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and Scala
 
Advance Java-Network Programming
Advance Java-Network ProgrammingAdvance Java-Network Programming
Advance Java-Network Programming
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
WebTalk - Implementing Web Services with a dedicated Java daemon
WebTalk - Implementing Web Services with a dedicated Java daemonWebTalk - Implementing Web Services with a dedicated Java daemon
WebTalk - Implementing Web Services with a dedicated Java daemon
 
Java Socket Programming
Java Socket ProgrammingJava Socket Programming
Java Socket Programming
 
Pemrograman Jaringan
Pemrograman JaringanPemrograman Jaringan
Pemrograman Jaringan
 
A.java
A.javaA.java
A.java
 
Mobile webapplication development
Mobile webapplication developmentMobile webapplication development
Mobile webapplication development
 
Socket Programming - nitish nagar
Socket Programming - nitish nagarSocket Programming - nitish nagar
Socket Programming - nitish nagar
 
Oredev 2009 JAX-RS
Oredev 2009 JAX-RSOredev 2009 JAX-RS
Oredev 2009 JAX-RS
 
KSDG-iSlide App 開發心得分享
KSDG-iSlide App 開發心得分享KSDG-iSlide App 開發心得分享
KSDG-iSlide App 開發心得分享
 
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 202010 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
 
Networking.ppt(client/server, socket) uses in program
Networking.ppt(client/server, socket) uses in programNetworking.ppt(client/server, socket) uses in program
Networking.ppt(client/server, socket) uses in program
 
Networking & Socket Programming In Java
Networking & Socket Programming In JavaNetworking & Socket Programming In Java
Networking & Socket Programming In Java
 
5.node js
5.node js5.node js
5.node js
 
Arduino práctico ethernet
Arduino práctico   ethernetArduino práctico   ethernet
Arduino práctico ethernet
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSockets
 
GWT Web Socket and data serialization
GWT Web Socket and data serializationGWT Web Socket and data serialization
GWT Web Socket and data serialization
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
 

Recently uploaded

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 

Recently uploaded (20)

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 

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