0% found this document useful (0 votes)
6 views30 pages

9 - Communica+ng Applica+ons: Advanced Compu+ng Tools For Applied Research

Communicating Application

Uploaded by

My Own
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views30 pages

9 - Communica+ng Applica+ons: Advanced Compu+ng Tools For Applied Research

Communicating Application

Uploaded by

My Own
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

9-­‐Communica+ng

 applica+ons  
 
Advanced  Compu+ng  Tools  for  Applied  Research  
 
(Herramientas  Computacionales  Avanzadas  para  la  Inves6gación  Aplicada)

Rafael  Palacios,  Jaime  Boal  


Advanced  Compu+ng  Tools  for  Applied  Research  
Contents  

Communica3ng  applica3ons  
 
1. Introduc3on  
2. Unix  command  line  
3. File-­‐based  data  exchange  
4. Inter-­‐process  communica3ons  
5. Database  connec3on  
6. AJAX  approach  

Ins+tuto  de  Inves+gación  Tecnológica   Advanced  Compu+ng  Tools  for  Applied  Research  
Escuela  Técnica  Superior  de  Ingeniería  ICAI   9-­‐Communica+ng  applica+ons   2  
1  

Introduc3on  
Introduc+on  
• Why  communica3ng  applica3ons?  
– We  can  use  the  best  applica3on  for  each  task  
– We  can  solve  the  same  problem  using  a  different  approach  
– We  can  move  the  data  into  the  environment  where  we  feel  more  
confident  (ex.  Matlab,  ex.  Excel)  

• In  the  case  of  machine-­‐to-­‐machine  communica3on,  we  can  


access  data  remotely  

Ins+tuto  de  Inves+gación  Tecnológica   Advanced  Compu+ng  Tools  for  Applied  Research  
Escuela  Técnica  Superior  de  Ingeniería  ICAI   9-­‐Communica+ng  applica+ons   4  
2  

Unix  command  line  


Unix  command  line  
• This  is  useful  for  automa3ng  data  pre-­‐processing  
• Only  valid  for  text-­‐based  applica3ons  
• It  is  available  in  several  systems:  
– Linux  
– Mac  OS  X  
– Other  Unix:  Solaris,  HP-­‐UX…  
– DOS  with  many  limita3ons  

Ins+tuto  de  Inves+gación  Tecnológica   Advanced  Compu+ng  Tools  for  Applied  Research  
Escuela  Técnica  Superior  de  Ingeniería  ICAI   9-­‐Communica+ng  applica+ons   6  
Unix  command  line  
• Unix  can  redirect  the  standard  input  and  the  standard  output  
of  any  program  

#prog

#prog >out.txt

#prog <in.txt >out.txt

Ins+tuto  de  Inves+gación  Tecnológica   Advanced  Compu+ng  Tools  for  Applied  Research  
Escuela  Técnica  Superior  de  Ingeniería  ICAI   9-­‐Communica+ng  applica+ons   7  
Unix  command  line  
• Unix  can  redirect  the  standard  input  and  the  standard  output  
of  any  program  

#prog

#prog >out.txt

#prog <in.txt >out.txt

input from keyboard

output to screen

Ins+tuto  de  Inves+gación  Tecnológica   Advanced  Compu+ng  Tools  for  Applied  Research  
Escuela  Técnica  Superior  de  Ingeniería  ICAI   9-­‐Communica+ng  applica+ons   8  
Unix  command  line  
• Unix  can  redirect  the  standard  input  and  the  standard  output  
of  any  program  

#prog

#prog >out.txt

#prog <in.txt >out.txt

input from keyboard

output to file out.txt

Ins+tuto  de  Inves+gación  Tecnológica   Advanced  Compu+ng  Tools  for  Applied  Research  
Escuela  Técnica  Superior  de  Ingeniería  ICAI   9-­‐Communica+ng  applica+ons   9  
Unix  command  line  
• Unix  can  redirect  the  standard  input  and  the  standard  output  
of  any  program  

#prog

#prog >out.txt

#prog <in.txt >out.txt

input from file in.txt

output to file out.txt

Ins+tuto  de  Inves+gación  Tecnológica   Advanced  Compu+ng  Tools  for  Applied  Research  
Escuela  Técnica  Superior  de  Ingeniería  ICAI   9-­‐Communica+ng  applica+ons   10  
Unix  command  line  (pipe)  
• Unix  can  convert  the  standard  output  of  one  program  into  the  
standard  input  of  another  

#prog1 | prog2 > out2.txt

• Example.  Command  du  to  compute  storage  requirements  of  


each  folder,  and  the  command  sort  to  display  ordered  by  size.  

#du –ks * | sort -n > big_folders.txt

Ins+tuto  de  Inves+gación  Tecnológica   Advanced  Compu+ng  Tools  for  Applied  Research  
Escuela  Técnica  Superior  de  Ingeniería  ICAI   9-­‐Communica+ng  applica+ons   11  
Unix  command  line  
• There  are  many  command  to  manipulate  text  
– head ß Extracts  lines  from  the  beginning  
– tail ß Extracts  lines  from  the  end
– grep ß Extracts  lines  according  to  a  given  pa`ern
– cut ß Extracts  columns
– tr ß Replaces  one  character  for  another  (example  comma  by  TAB)
– sed ß Useful  for  replacing  strings  (example  "OFF"  by  "0")  
– sort ß Sorts  lines  
– curl ß Downloads  data  from  websites  
• This  is  very  useful  for  pre-­‐processing  data  
– Very  efficient  
– Completely  automa3c  
– Commands  could  be  stored  in  scripts  

Ins+tuto  de  Inves+gación  Tecnológica   Advanced  Compu+ng  Tools  for  Applied  Research  
Escuela  Técnica  Superior  de  Ingeniería  ICAI   9-­‐Communica+ng  applica+ons   12  
3  

File-­‐based  data  exchange  


Files  
• The  most  common  way  to  transfer  data  from  one  program  to  
another  is  to  store  such  data  into  a  temporary  file.  
• Some3mes  menu  op3ons  for  export  and  import  are  available.  

Program 1

Program 2
Data File

Ins+tuto  de  Inves+gación  Tecnológica   Advanced  Compu+ng  Tools  for  Applied  Research  
Escuela  Técnica  Superior  de  Ingeniería  ICAI   9-­‐Communica+ng  applica+ons   14  
Files  
• Some  typical  formats:  
– CSV  (comma  separated  values)  
– TAB  separated  values  
– XML  (Extensible  Markup  Language)  
• Most  robust  method  
• Very  flexible  
• Very  inefficient  
– Binary  formats.    Only  for  compa3ble  applica3ons  
– Other  common  specific  formats:  
• XLS  Excel  
• SHP  (ESRI  Shape  Format,  ARCview)  
• KML/KML  (Google  Earth)  

Ins+tuto  de  Inves+gación  Tecnológica   Advanced  Compu+ng  Tools  for  Applied  Research  
Escuela  Técnica  Superior  de  Ingeniería  ICAI   9-­‐Communica+ng  applica+ons   15  
Files  –  some  comments  on  performance  
• Reading  and  wri3ng  text  files  (or  XML  files)  is  not  efficient.  
• Binary  files  are  very  efficient.  Some3mes  they  are  just  memory  
dumps.  
• Hard  drive  access  3me  is  100,000  3mes  slower  that  RAM  and  
data  transfer  is  1000  3mes  slower  that  RAM  
• However:  
– In  some  Unix  systems  (Ex.  Solaris)  the  folder  /tmp  is  a  RAM  disk  
as  long  as  enough  RAM  is  available.  
– Solid  State  HDs  are  made  of  RAM  memory  

Ins+tuto  de  Inves+gación  Tecnológica   Advanced  Compu+ng  Tools  for  Applied  Research  
Escuela  Técnica  Superior  de  Ingeniería  ICAI   9-­‐Communica+ng  applica+ons   16  
4  

IPC:  Inter-­‐process  communica3ons  


IPC  -­‐  introduc+on  
• IPC  is  a  mechanism  to  exchange  data  directly  between  
processes.  
• Avoids  temporary  files  
• Requires  specific  programming  

Program 1

Program 2
Data File

Ins+tuto  de  Inves+gación  Tecnológica   Advanced  Compu+ng  Tools  for  Applied  Research  
Escuela  Técnica  Superior  de  Ingeniería  ICAI   9-­‐Communica+ng  applica+ons   18  
IPC  –  Different  types  
• Inside  the  same  computer  
– Mul3tasking  computer  
– Ex.  a  program  for  data  acquisi3on  and  another  for  displaying  

• Machine-­‐to-­‐Machine  communica3ons  
– A  network  connec3on  is  required  
– Concerns  about  security  
– Ex.  Web  services,  web-­‐based  applica3ons,  client-­‐server  model  

Ins+tuto  de  Inves+gación  Tecnológica   Advanced  Compu+ng  Tools  for  Applied  Research  
Escuela  Técnica  Superior  de  Ingeniería  ICAI   9-­‐Communica+ng  applica+ons   19  
IPC  techniques  (single  computer)  
• Pipes  
– Unix  stdin/stdout  redirec3on  
– popen  func3on  

• Shared  memory  
– Usually  requires  using  semaphores  to  control  concurrency  
– Several  processes  can  share  data  simultaneously  
– Message  queues  is  a  specific  type  of  SHM  

• Signals  
– Just  for  no3fica3on,  no  data  can  be  sent  with  signals  

Ins+tuto  de  Inves+gación  Tecnológica   Advanced  Compu+ng  Tools  for  Applied  Research  
Escuela  Técnica  Superior  de  Ingeniería  ICAI   9-­‐Communica+ng  applica+ons   20  
IPC  techniques  (machine-­‐to-­‐machine)  
• Sockets  (Berkeley  sockets)  
– Originally  implemented  in  BSD  Unix  
– Used  by  most  (all)  TCP  applica3ons  

• Message  passing  
– Used  by  MPI  (parallel  compu3ng)  
– Java  RMI  (Java  Remote  Method  Invoca3on)  

Ins+tuto  de  Inves+gación  Tecnológica   Advanced  Compu+ng  Tools  for  Applied  Research  
Escuela  Técnica  Superior  de  Ingeniería  ICAI   9-­‐Communica+ng  applica+ons   21  
5  

Database  connec3on  
Database  connec+on  
• A  database  may  be  used  to  exchange  informa3on  in  a  similar  
way  as  the  file  exchange  approach  
• Several  programs  can  access  the  data  at  the  same  3me  

Database
server

Program 3

Program 2
Program 1

Ins+tuto  de  Inves+gación  Tecnológica   Advanced  Compu+ng  Tools  for  Applied  Research  
Escuela  Técnica  Superior  de  Ingeniería  ICAI   9-­‐Communica+ng  applica+ons   23  
Databases:  Matlab  example  
%This example requiere Matlab's Database toolbox

conn=database('MyConn', '', ''); %'MyConn' is the ODBC name (DSN name)


if ~isempty(conn.Message)
error(conn.Message);
end
query=['select * from usuarios'];

cur=exec(conn,query);
if (~isempty(cur.Message))
fprintf(['Error menssage:
',cur.Message,'\nQuery :',cur.SQLQuery,'\n']);
error('ConsultaTable');
end
curs=fetch(cur);

dat=curs.Data;

close(conn);

Ins+tuto  de  Inves+gación  Tecnológica   Advanced  Compu+ng  Tools  for  Applied  Research  
Escuela  Técnica  Superior  de  Ingeniería  ICAI   9-­‐Communica+ng  applica+ons   24  
Databases:  PHP  example  
$conn=mysql_connect(localhost, "$username", "$password");
mysql_select_db("personel",$conn);

$query = "SELECT * from users";


$result = mysql_query($query,$conn);
if ($row=mysql_fetch_array($result)) {
while ($row) {
print "Name: {$row['name']} {$row['lastname']} <br>\n";
$row=mysql_fetch_row($result);
}
}
mysql_free_result($result);
mysql_close($conn);

Ins+tuto  de  Inves+gación  Tecnológica   Advanced  Compu+ng  Tools  for  Applied  Research  
Escuela  Técnica  Superior  de  Ingeniería  ICAI   9-­‐Communica+ng  applica+ons   25  
6  

AJAX  approach  
AJAX  
• JavaScript  applica3ons  communicate  with  web  server  to  get  
updated  data  
Web server

HTML and JavaScript

Database

Ins+tuto  de  Inves+gación  Tecnológica   Advanced  Compu+ng  Tools  for  Applied  Research  
Escuela  Técnica  Superior  de  Ingeniería  ICAI   9-­‐Communica+ng  applica+ons   27  
AJAX  example  2  
//HTML objects

<select name="areas" onchange="MyAJAX(this.value);">


<option>--Select Area--</option>
<option value="13">ASI</option>
<option value="11">ADI</option>
<option value="14">GEA</option>
<option value="15">ASF</option>
<option value="1">REDES</option>
<option value="2">MAC</option>
<option value="3">SADSE</option> JavaScript function to be called
<option value="4">RYE</option>
</select>

<br>

<div id="list">
</div>

Empty container

Ins+tuto  de  Inves+gación  Tecnológica   Advanced  Compu+ng  Tools  for  Applied  Research  
Escuela  Técnica  Superior  de  Ingeniería  ICAI   9-­‐Communica+ng  applica+ons   28  
AJAX  example  2  
//JavaScript function
function MyAJAX(value)
{
var destination=document.getElementById("list");
var doc = null;

doc = new XMLHttpRequest();


if (doc){
var my_url="http://www.iit.upcomillas.es/palacios/act/consulta_area.php?area="+value;
doc.open("GET", my_url, false);
doc.send(null);

//store result in list object


destination.innerHTML = doc.responseText;
}else{
destination.innerHTML = 'Browser unable to create XMLHttp Object';
}
}

Ins+tuto  de  Inves+gación  Tecnológica   Advanced  Compu+ng  Tools  for  Applied  Research  
Escuela  Técnica  Superior  de  Ingeniería  ICAI   9-­‐Communica+ng  applica+ons   29  
 
Instituto de Investigación Tecnológica
C/ Santa Cruz de Marcenado, nº 26
28015 Madrid
Tel +34 91 542 28 00
Fax + 34 91 542 31 76
info@iit.upcomillas.es
                     

www.iit.upcomillas.es

You might also like