Tutorial Addendum on Perl - Allotment B - Atrium Advice

adventuregamesios educationappsios musicappsios
 31 December 18:00   

    



    



    

This affiliate explains:

    



        

  • What is a socket.

        



  •     

  • How to authorize a atrium communication.

        



  •     

  • A simple archetype of atrium server application.

        



  •     

  • A simple archetype of atrium applicant application.

        



  •     

  • Built-in arrangement account functions.

        



  •     

  • Socket module.

        



  •     



    



    



    

What Is a Socket

    



    

Socket: An abstraction represents one end-point of a two-way communication

    

link amid two programs active on the Internet network.

    



    

Internet Address: A different amount to analyze anniversary computer arrangement on

    

the Internet.

    



    

Port: A amount apery an access point of on a computer arrangement on

    

the Internet, area a two-way advice hotlink can be established.

    



    

Local System: The computer arrangement at this end of a two-way communication

    

link.

    



    

Remote System: The computer arrangement at the additional end of a two-way

    

communication link.

    



    

A two-way advice hotlink on the Internet involves:

    



        

  • Two computer systems, anniversary has its own Internet address.


  •     

  • A anchorage amount on anniversary computer arrangement that is acclimated alone by this

        

    communication link.



  •     

  • An appliance program on anniversary computer arrangement that uses this

        

    communication link.



  •     

  • A atrium handle created in the appliance program that represents

        

    this advice link.



  •     

  • The appliance program can use the atrium as a analytic ascribe or

        

    output accessory to accept or forward data from or to the appliance program

        

    running at the additional end of the advice link.



  •     

  • The appliance program can aswell concern the atrium for advice

        

    about the advice link, like: The Internet abode and anchorage amount

        

    at this end of the advice link; The Internet abode and anchorage amount

        

    at the additional end of the advice link.



  •     



    



    

The afterward diagram illustrates how an appliance program can use a atrium

    

to allocution with additional appliance program active on addition computer system

    

through a two-way advice hotlink on the Internet:

    



    

Computer Arrangement I Computer Arrangement II

    



    

 

    

i/o |Address a| Internet |Address b| i/o

    

App. A<--->Socket|Port 1 |<-------------->| Anchorage 2|Socket<--->App. B

    



    



    



    

Establishing a Atrium Communication

    



    

In the antecedent section, we alone discussed about how atrium works with

    

a advice hotlink that has been accustomed already. Now, let s see

    

how two appliance programs can authorize a advice hotlink between

    

them.

    



    

To authorize a advice link, one appliance program haveto act

    

as a server , make a server atrium with a accustomed anchorage number, and

    

set the server atrium in the accept approach cat-and-mouse for a affiliation request

    

from additional program.

    



    

With one program active as a server alert for a affiliation request

    

at a specific anchorage number, the additional program can now make atrium with

    

a accustomed bounded anchorage number, the Internet abode of the computer arrangement

    

where the first program is running, and the anchorage amount area the server

    

socket is listening. At this time, a affix appeal will be forward over

    

to the server socket. The server atrium should then acquire the affix

    

request and instantiate a atrium item to complete advice link.

    



    

Perl offers several congenital functions to abutment atrium communication:

    



    

socket() - Creates a atrium handle for the defined advice domain, blazon and protocol.

    

For example:

    



    

$domain = 2; # Internet domain

    

$type = 1; # Sequenced, reliable, two-way connection, byte streams

    

$proto = 6; # Manual Ascendancy Agreement (TCP)

    

socket(SOCK,$domain,$type,$proto);

    



    



    

bind() - Binds a atrium handle to a bounded abode that represents a anchorage on the bounded system.

    

For example:

    



    

$domain = 2; # Internet domain

    

$host = pack( C4 , 127,0,0,1); # localhost = 127.0.0.1

    

$port = 8888;

    

$address = pack( S n a4 x8 , $domain, $port, $host);

    

bind(SOCK, $address);

    



    



    

Note that host IP abode haveto be arranged into a 4-byte number, then put it into

    

the abode anatomy with the anchorage amount using the afterward architecture codes:

    



    

S An bearding abbreviate value. 16 bits

    

n An bearding abbreviate in "network" (big-endian) order. 16 bits

    

a A cord with approximate bifold data, will be absent padded.

    

x A absent byte.

    



    



    

 


Tags: internet, address, computer, program, system, example, server, application, handle, network, connection, communication, represents, domain

 socket, communication, internet, system, computer, application, program, address, domain, server, local, running, example, establish, connection, handle, represents, network, , communication link, computer system, port number, application program, internet address, program can, link the, server socket, socket communication, domain type, socket handle, way communication, way communication link, computer system that,

Share Tutorial Addendum on Perl - Allotment B - Atrium Advice:
Digg it!   Google Bookmarks   Del.icio.us   Yahoo! MyWeb   Furl  Binklist   Reddit!   Stumble Upon   Technorati   Windows Live   Bookmark

Text link code :
Hyper link code:

Also see ...

Permalink
Article In : Computers & Technology  -  perl