SlideShare uma empresa Scribd logo
1 de 22
Baixar para ler offline
Perl Programming
                 Course
            Network programming




Krassimir Berov

I-can.eu
Contents
1. Sockets, servers and clients
2. TCP/IP, UDP sockets
3. Unix Domain Socket (UDS) sockets
4. IO::Socket
5. HTTP and SMTP
6. LWP and WWW::Mechanize
Sockets, servers and clients

• Socket
  • an end-point of a bi-directional communication link
    in the Berkeley sockets API
  • Berkeley sockets API allows communications
    between hosts or between processes on one
    computer
  • One of the fundamental technologies underlying the
    Internet.
  • A network socket is a communication end-point
    unique to a machine communicating on an Internet
    Protocol-based network, such as the Internet.
  • Unix domain socket, an end-point
    in local inter-process communication
Sockets, servers and clients

• Server
  • An application or device that performs
    services for connected clients as part of a
    client-server architecture
  • An application program that accepts
    connections in order to service requests by
    sending back responses
  • Example:
    web servers(Apache), e-mail servers(Postfix),
    file servers
Sockets, servers and clients

• Client
  • An application or system that accesses a
    (remote) service on another computer
    system known as a server
  • Example:
    Web browsers (Internet Explorer, Opera,
    Firefox)
    Mail Clients (Thunderbird, KMail, MS
    Outlook)
TCP/IP, UDP sockets
• An Internet socket is composed of
  • Protocol (TCP, UDP, raw IP)
  • Local IP address
  • Local port
  • Remote IP address
  • Remote port
Unix Domain Socket
• A Unix domain socket (UDS)
  or IPC socket
  • inter-process communication socket
  • a virtual socket
  • similar to an internet socket
  • used in POSIX operating systems for inter-
    process communication
     • connections appear as byte streams, much like
       network connections,
     • all data remains within the local computer
IO::Socket
• IO::Socket - Object interface to socket
  communications
  • built upon the IO::Handle interface and inherits
    all its methods
  • only defines methods for operations common to
    all types of socket
  • Operations, specified to a socket in a particular
    domain have methods defined in sub classes
  • will export all functions (and constants) defined
    by Socket
IO::Socket
• IO::Socket – Example (TCP/IP)
  #io-socket-tcp-client.pl
  use IO::Socket;
  my $sock = IO::Socket::INET->new(
      PeerAddr => $host,
      PeerPort => "$port",
      Proto => 'tcp',
      Timeout => 60
  ) or die $@;

  die "Could not connect to $host$/"
      unless $sock->connected;

  #...
IO::Socket
• IO::Socket – Example 2 (TCP/IP)
  #io-socket-tcp-server.pl
  use IO::Socket;
  my ($host, $port, $path ) = ( 'localhost', 8088 );
  my $server = new IO::Socket::INET (
       LocalAddr => $host,
       LocalPort => $port,
       Proto => 'tcp',
       Listen => 10,
       Type      => SOCK_STREAM,
       ReuseAddr => 1
  );
  print "Server ($0) running on port $port...n";
  while (my $connection = $server->accept) {
  #...
IO::Socket
• IO::Socket – Example (UDS)
 #io-socket-uds-server.pl
 use IO::Socket;
 my $file = "./udssock";
 unlink $file;
 my $server = IO::Socket::UNIX->new(
     Local => $file,
     Type   => SOCK_STREAM,
     Listen => 5
 ) or die $@;

 print "Server running on file $file...n";
 #...
IO::Socket
• IO::Socket – Example 2 (UDS)
 #io-socket-uds-client.pl
 use IO::Socket;
 my $server = IO::Socket::UNIX->new(
     Peer => "./udssock",
 ) or die $@;

 # communicate with the server
 print "Client connected.n";
 print "Server says: ", $server->getline;
 $server->print("Hello from the client!n");
 $server->print("And goodbye!n");
 $server->close;
 #...
IO::Socket
• IO::Socket – Example (UDP)
 #io-socket-udp-server.pl
 use IO::Socket;
 my $port = 4444;
 my $server = new IO::Socket::INET(
    LocalPort => $port,
    Proto     => 'udp',
 );
 die "Bind failed: $!n" unless $server;
 print "Server running on port $port...n";
 #...
IO::Socket
• IO::Socket – Example 2 (UDP)
 #io-socket-udp-client.pl
 use IO::Socket;
 my $host = 'localhost';
 my $port = 4444;
 my $client = new IO::Socket::INET(
      PeerAddr => $host,
      PeerPort => $port,
      Timeout => 2,
      Proto    => 'udp',
 );
 $client->send("Hello from client") or die "Send: $!n";
 my $message;
 $client->recv($message, 1024, 0);
 print "Response was: $messagen";
 #...
HTTP and SMTP
• HTTP
• SMTP
Sending Mail
• Net::SMTP
 #smtp.pl
 use Net::SMTP;
 my $smtp = Net::SMTP->new(
     Host => 'localhost',
     Timeout => 30,
     Hello =>'localhost',
 );
 my $from = 'me@example.com';
 my @to   = ('you@example.org',);
 my $text = $ARGV[0]|| 'проба';
 my $mess = "ERROR: Can't send mail using Net::SMTP. ";
 $smtp->mail( $from ) || die $mess;
 $smtp->to( @to, { SkipBad => 1 } ) || die $mess;
 $smtp->data( $text ) || die $mess;
 $smtp->dataend() || die $mess;
 $smtp->quit();
LWP and WWW::Mechanize
• LWP - The World-Wide Web library for Perl
  • provides a simple and consistent application
    programming interface (API)
    to the World-Wide Web
  • classes and functions that allow you to write
    WWW clients
  • also contains modules that help you implement
    simple HTTP servers
  • supports access to http, https, gopher, ftp, news,
    file, and mailto resources
  • transparent redirect, parser for robots.txt files
    etc...
LWP and WWW::Mechanize
• WWW::Mechanize - Handy web browsing in a
  Perl object
  • helps you automate interaction with a website

  • well suited for use in testing web applications

  • is a proper subclass of LWP::UserAgent

  • you can also use any of the LWP::UserAgent's
    methods.
LWP and WWW::Mechanize
• WWW::Mechanize - Example
  • helps you automate interaction with a website

  • well suited for use in testing web applications

  • is a proper subclass of LWP::UserAgent

  • you can also use any of the LWP::UserAgent's
    methods.
LWP and WWW::Mechanize
• Example – getting product data from a site
 #www_mech.pl
 use strict; use warnings;
 use MyMech;
 use Data::Dumper;
 #Config
 $MyMech::Config->{DEBUG}=0;
 my $Config = $MyMech::Config;
 #print Dumper($Config);
 my $mech = MyMech->new(
      agent      => $Config->{agent},
      cookie_jar => $Config->{cookie_jar},
      autocheck => $Config->{autocheck},
      onwarn     => $Config->{onwarn}
 );
 #...
Network programming
• Resources
  • Beginning Perl
    (Chapter 14 – The World of Perl/IPC and
    Networking)
  • Professional Perl Programming
    (Chapter 23 – Networking with Perl)
  • perldoc perlipc
  • perldoc IO::Socket
  • http://en.wikipedia.org/wiki/Berkeley_sockets
  • Perl & LWP (http://lwp.interglacial.com/)
Network programming




Questions?

Mais conteúdo relacionado

Mais procurados (20)

Ch 3 event driven programming
Ch 3 event driven programmingCh 3 event driven programming
Ch 3 event driven programming
 
Http Vs Https .
Http Vs Https . Http Vs Https .
Http Vs Https .
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
 
HyperText Transfer Protocol (HTTP)
HyperText Transfer Protocol (HTTP)HyperText Transfer Protocol (HTTP)
HyperText Transfer Protocol (HTTP)
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Socket programming in Java (PPTX)
Socket programming in Java (PPTX)Socket programming in Java (PPTX)
Socket programming in Java (PPTX)
 
Java I/o streams
Java I/o streamsJava I/o streams
Java I/o streams
 
Synchronization.37
Synchronization.37Synchronization.37
Synchronization.37
 
Networking in Java
Networking in JavaNetworking in Java
Networking in Java
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Handling I/O in Java
Handling I/O in JavaHandling I/O in Java
Handling I/O in Java
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 
PHP - Introduction to File Handling with PHP
PHP -  Introduction to  File Handling with PHPPHP -  Introduction to  File Handling with PHP
PHP - Introduction to File Handling with PHP
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
File handling-c
File handling-cFile handling-c
File handling-c
 
Files in java
Files in javaFiles in java
Files in java
 
Control structure C++
Control structure C++Control structure C++
Control structure C++
 
Application layer protocol - Electronic Mail
Application layer protocol - Electronic MailApplication layer protocol - Electronic Mail
Application layer protocol - Electronic Mail
 

Destaque (17)

Sockets
SocketsSockets
Sockets
 
Aulas de Java Avançado 2- Faculdade iDez 2010
Aulas de Java Avançado 2- Faculdade iDez 2010Aulas de Java Avançado 2- Faculdade iDez 2010
Aulas de Java Avançado 2- Faculdade iDez 2010
 
Pyhug zmq
Pyhug zmqPyhug zmq
Pyhug zmq
 
Aula sockets
Aula socketsAula sockets
Aula sockets
 
Aplicações Web Ricas e Acessíveis
Aplicações Web Ricas e AcessíveisAplicações Web Ricas e Acessíveis
Aplicações Web Ricas e Acessíveis
 
Lidando com Erros - Android
Lidando com Erros - AndroidLidando com Erros - Android
Lidando com Erros - Android
 
Linguagem PHP
Linguagem PHPLinguagem PHP
Linguagem PHP
 
Linguagem PHP para principiantes
Linguagem PHP para principiantesLinguagem PHP para principiantes
Linguagem PHP para principiantes
 
Módulo-6-7-ip-com-sockets
Módulo-6-7-ip-com-socketsMódulo-6-7-ip-com-sockets
Módulo-6-7-ip-com-sockets
 
Tecnologia java para sockets
Tecnologia java para socketsTecnologia java para sockets
Tecnologia java para sockets
 
Redes 1 - Sockets em C#
Redes 1 - Sockets em C#Redes 1 - Sockets em C#
Redes 1 - Sockets em C#
 
Socket programming with php
Socket programming with phpSocket programming with php
Socket programming with php
 
correção Ficha 4,5,6,e 7
correção Ficha 4,5,6,e 7correção Ficha 4,5,6,e 7
correção Ficha 4,5,6,e 7
 
Programming TCP/IP with Sockets
Programming TCP/IP with SocketsProgramming TCP/IP with Sockets
Programming TCP/IP with Sockets
 
Basic socket programming
Basic socket programmingBasic socket programming
Basic socket programming
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Socket Programming Tutorial
Socket Programming TutorialSocket Programming Tutorial
Socket Programming Tutorial
 

Semelhante a Network programming

Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)dantleech
 
2019 11-bgphp
2019 11-bgphp2019 11-bgphp
2019 11-bgphpdantleech
 
Introduction to Node.js: What, why and how?
Introduction to Node.js: What, why and how?Introduction to Node.js: What, why and how?
Introduction to Node.js: What, why and how?Christian Joudrey
 
Running Head IMPLEMENTING THE LIST AND SEARCH FEATURES IN THE DIS.docx
Running Head IMPLEMENTING THE LIST AND SEARCH FEATURES IN THE DIS.docxRunning Head IMPLEMENTING THE LIST AND SEARCH FEATURES IN THE DIS.docx
Running Head IMPLEMENTING THE LIST AND SEARCH FEATURES IN THE DIS.docxcowinhelen
 
Learn Electron for Web Developers
Learn Electron for Web DevelopersLearn Electron for Web Developers
Learn Electron for Web DevelopersKyle Cearley
 
Rails web api 开发
Rails web api 开发Rails web api 开发
Rails web api 开发shaokun
 
Socket programming-tutorial-sk
Socket programming-tutorial-skSocket programming-tutorial-sk
Socket programming-tutorial-sksureshkarthick37
 
AnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webAnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webclkao
 
Asynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time MessagingAsynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time MessagingSteve Rhoades
 
Service Discovery using etcd, Consul and Kubernetes
Service Discovery using etcd, Consul and KubernetesService Discovery using etcd, Consul and Kubernetes
Service Discovery using etcd, Consul and KubernetesSreenivas Makam
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with PuppetKris Buytaert
 
How to automate all your SEO projects
How to automate all your SEO projectsHow to automate all your SEO projects
How to automate all your SEO projectsVincent Terrasi
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with ExamplesGabriele Lana
 
Nodejsexplained 101116115055-phpapp02
Nodejsexplained 101116115055-phpapp02Nodejsexplained 101116115055-phpapp02
Nodejsexplained 101116115055-phpapp02Sunny Gupta
 
Puppet Camp Charlotte 2015: Exporting Resources: There and Back Again
Puppet Camp Charlotte 2015: Exporting Resources: There and Back AgainPuppet Camp Charlotte 2015: Exporting Resources: There and Back Again
Puppet Camp Charlotte 2015: Exporting Resources: There and Back AgainPuppet
 

Semelhante a Network programming (20)

A.java
A.javaA.java
A.java
 
Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)
 
java networking
 java networking java networking
java networking
 
2019 11-bgphp
2019 11-bgphp2019 11-bgphp
2019 11-bgphp
 
Introduction to Node.js: What, why and how?
Introduction to Node.js: What, why and how?Introduction to Node.js: What, why and how?
Introduction to Node.js: What, why and how?
 
Running Head IMPLEMENTING THE LIST AND SEARCH FEATURES IN THE DIS.docx
Running Head IMPLEMENTING THE LIST AND SEARCH FEATURES IN THE DIS.docxRunning Head IMPLEMENTING THE LIST AND SEARCH FEATURES IN THE DIS.docx
Running Head IMPLEMENTING THE LIST AND SEARCH FEATURES IN THE DIS.docx
 
Learn Electron for Web Developers
Learn Electron for Web DevelopersLearn Electron for Web Developers
Learn Electron for Web Developers
 
Rack
RackRack
Rack
 
Rails web api 开发
Rails web api 开发Rails web api 开发
Rails web api 开发
 
Socket programming-tutorial-sk
Socket programming-tutorial-skSocket programming-tutorial-sk
Socket programming-tutorial-sk
 
AnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webAnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time web
 
Write php deploy everywhere tek11
Write php deploy everywhere   tek11Write php deploy everywhere   tek11
Write php deploy everywhere tek11
 
Python, do you even async?
Python, do you even async?Python, do you even async?
Python, do you even async?
 
Asynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time MessagingAsynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time Messaging
 
Service Discovery using etcd, Consul and Kubernetes
Service Discovery using etcd, Consul and KubernetesService Discovery using etcd, Consul and Kubernetes
Service Discovery using etcd, Consul and Kubernetes
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with Puppet
 
How to automate all your SEO projects
How to automate all your SEO projectsHow to automate all your SEO projects
How to automate all your SEO projects
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
 
Nodejsexplained 101116115055-phpapp02
Nodejsexplained 101116115055-phpapp02Nodejsexplained 101116115055-phpapp02
Nodejsexplained 101116115055-phpapp02
 
Puppet Camp Charlotte 2015: Exporting Resources: There and Back Again
Puppet Camp Charlotte 2015: Exporting Resources: There and Back AgainPuppet Camp Charlotte 2015: Exporting Resources: There and Back Again
Puppet Camp Charlotte 2015: Exporting Resources: There and Back Again
 

Mais de Krasimir Berov (Красимир Беров) (15)

Хешове
ХешовеХешове
Хешове
 
Списъци и масиви
Списъци и масивиСписъци и масиви
Списъци и масиви
 
Скаларни типове данни
Скаларни типове данниСкаларни типове данни
Скаларни типове данни
 
Въведение в Perl
Въведение в PerlВъведение в Perl
Въведение в Perl
 
System Programming and Administration
System Programming and AdministrationSystem Programming and Administration
System Programming and Administration
 
Processes and threads
Processes and threadsProcesses and threads
Processes and threads
 
Working with databases
Working with databasesWorking with databases
Working with databases
 
Working with text, Regular expressions
Working with text, Regular expressionsWorking with text, Regular expressions
Working with text, Regular expressions
 
Subroutines
SubroutinesSubroutines
Subroutines
 
IO Streams, Files and Directories
IO Streams, Files and DirectoriesIO Streams, Files and Directories
IO Streams, Files and Directories
 
Syntax
SyntaxSyntax
Syntax
 
Hashes
HashesHashes
Hashes
 
Lists and arrays
Lists and arraysLists and arrays
Lists and arrays
 
Scalar data types
Scalar data typesScalar data types
Scalar data types
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 

Último

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Último (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

Network programming

  • 1. Perl Programming Course Network programming Krassimir Berov I-can.eu
  • 2. Contents 1. Sockets, servers and clients 2. TCP/IP, UDP sockets 3. Unix Domain Socket (UDS) sockets 4. IO::Socket 5. HTTP and SMTP 6. LWP and WWW::Mechanize
  • 3. Sockets, servers and clients • Socket • an end-point of a bi-directional communication link in the Berkeley sockets API • Berkeley sockets API allows communications between hosts or between processes on one computer • One of the fundamental technologies underlying the Internet. • A network socket is a communication end-point unique to a machine communicating on an Internet Protocol-based network, such as the Internet. • Unix domain socket, an end-point in local inter-process communication
  • 4. Sockets, servers and clients • Server • An application or device that performs services for connected clients as part of a client-server architecture • An application program that accepts connections in order to service requests by sending back responses • Example: web servers(Apache), e-mail servers(Postfix), file servers
  • 5. Sockets, servers and clients • Client • An application or system that accesses a (remote) service on another computer system known as a server • Example: Web browsers (Internet Explorer, Opera, Firefox) Mail Clients (Thunderbird, KMail, MS Outlook)
  • 6. TCP/IP, UDP sockets • An Internet socket is composed of • Protocol (TCP, UDP, raw IP) • Local IP address • Local port • Remote IP address • Remote port
  • 7. Unix Domain Socket • A Unix domain socket (UDS) or IPC socket • inter-process communication socket • a virtual socket • similar to an internet socket • used in POSIX operating systems for inter- process communication • connections appear as byte streams, much like network connections, • all data remains within the local computer
  • 8. IO::Socket • IO::Socket - Object interface to socket communications • built upon the IO::Handle interface and inherits all its methods • only defines methods for operations common to all types of socket • Operations, specified to a socket in a particular domain have methods defined in sub classes • will export all functions (and constants) defined by Socket
  • 9. IO::Socket • IO::Socket – Example (TCP/IP) #io-socket-tcp-client.pl use IO::Socket; my $sock = IO::Socket::INET->new( PeerAddr => $host, PeerPort => "$port", Proto => 'tcp', Timeout => 60 ) or die $@; die "Could not connect to $host$/" unless $sock->connected; #...
  • 10. IO::Socket • IO::Socket – Example 2 (TCP/IP) #io-socket-tcp-server.pl use IO::Socket; my ($host, $port, $path ) = ( 'localhost', 8088 ); my $server = new IO::Socket::INET ( LocalAddr => $host, LocalPort => $port, Proto => 'tcp', Listen => 10, Type => SOCK_STREAM, ReuseAddr => 1 ); print "Server ($0) running on port $port...n"; while (my $connection = $server->accept) { #...
  • 11. IO::Socket • IO::Socket – Example (UDS) #io-socket-uds-server.pl use IO::Socket; my $file = "./udssock"; unlink $file; my $server = IO::Socket::UNIX->new( Local => $file, Type => SOCK_STREAM, Listen => 5 ) or die $@; print "Server running on file $file...n"; #...
  • 12. IO::Socket • IO::Socket – Example 2 (UDS) #io-socket-uds-client.pl use IO::Socket; my $server = IO::Socket::UNIX->new( Peer => "./udssock", ) or die $@; # communicate with the server print "Client connected.n"; print "Server says: ", $server->getline; $server->print("Hello from the client!n"); $server->print("And goodbye!n"); $server->close; #...
  • 13. IO::Socket • IO::Socket – Example (UDP) #io-socket-udp-server.pl use IO::Socket; my $port = 4444; my $server = new IO::Socket::INET( LocalPort => $port, Proto => 'udp', ); die "Bind failed: $!n" unless $server; print "Server running on port $port...n"; #...
  • 14. IO::Socket • IO::Socket – Example 2 (UDP) #io-socket-udp-client.pl use IO::Socket; my $host = 'localhost'; my $port = 4444; my $client = new IO::Socket::INET( PeerAddr => $host, PeerPort => $port, Timeout => 2, Proto => 'udp', ); $client->send("Hello from client") or die "Send: $!n"; my $message; $client->recv($message, 1024, 0); print "Response was: $messagen"; #...
  • 15. HTTP and SMTP • HTTP • SMTP
  • 16. Sending Mail • Net::SMTP #smtp.pl use Net::SMTP; my $smtp = Net::SMTP->new( Host => 'localhost', Timeout => 30, Hello =>'localhost', ); my $from = 'me@example.com'; my @to = ('you@example.org',); my $text = $ARGV[0]|| 'проба'; my $mess = "ERROR: Can't send mail using Net::SMTP. "; $smtp->mail( $from ) || die $mess; $smtp->to( @to, { SkipBad => 1 } ) || die $mess; $smtp->data( $text ) || die $mess; $smtp->dataend() || die $mess; $smtp->quit();
  • 17. LWP and WWW::Mechanize • LWP - The World-Wide Web library for Perl • provides a simple and consistent application programming interface (API) to the World-Wide Web • classes and functions that allow you to write WWW clients • also contains modules that help you implement simple HTTP servers • supports access to http, https, gopher, ftp, news, file, and mailto resources • transparent redirect, parser for robots.txt files etc...
  • 18. LWP and WWW::Mechanize • WWW::Mechanize - Handy web browsing in a Perl object • helps you automate interaction with a website • well suited for use in testing web applications • is a proper subclass of LWP::UserAgent • you can also use any of the LWP::UserAgent's methods.
  • 19. LWP and WWW::Mechanize • WWW::Mechanize - Example • helps you automate interaction with a website • well suited for use in testing web applications • is a proper subclass of LWP::UserAgent • you can also use any of the LWP::UserAgent's methods.
  • 20. LWP and WWW::Mechanize • Example – getting product data from a site #www_mech.pl use strict; use warnings; use MyMech; use Data::Dumper; #Config $MyMech::Config->{DEBUG}=0; my $Config = $MyMech::Config; #print Dumper($Config); my $mech = MyMech->new( agent => $Config->{agent}, cookie_jar => $Config->{cookie_jar}, autocheck => $Config->{autocheck}, onwarn => $Config->{onwarn} ); #...
  • 21. Network programming • Resources • Beginning Perl (Chapter 14 – The World of Perl/IPC and Networking) • Professional Perl Programming (Chapter 23 – Networking with Perl) • perldoc perlipc • perldoc IO::Socket • http://en.wikipedia.org/wiki/Berkeley_sockets • Perl & LWP (http://lwp.interglacial.com/)