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)

Bash shell scripting
Bash shell scriptingBash shell scripting
Bash shell scripting
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
 
Delegates and events in C#
Delegates and events in C#Delegates and events in C#
Delegates and events in C#
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Dhcp server configuration
Dhcp server configurationDhcp server configuration
Dhcp server configuration
 
Fragment
Fragment Fragment
Fragment
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
 
Networking in Java
Networking in JavaNetworking in Java
Networking in Java
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
 
Introduction to Network and System Administration
Introduction to Network and System AdministrationIntroduction to Network and System Administration
Introduction to Network and System Administration
 
Shell programming
Shell programmingShell programming
Shell programming
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cycle
 
process creation OS
process creation OSprocess creation OS
process creation OS
 
Math functions in javascript
Math functions in javascriptMath functions in javascript
Math functions in javascript
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Java Thread Synchronization
Java Thread SynchronizationJava Thread Synchronization
Java Thread Synchronization
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
 

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

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 

Último (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 

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/)