Tutorial Addendum on Perl - Allotment B - Atrium Advice
| |
In the telnet window, blazon in the afterward text:
Fish, I adulation you and account you actual much.
But I will annihilate you asleep afore this day ends.
.
The argument will be antipodal and alternate aback from the ReverseEchoer.pl:
Welcome to About-face Answer Server.
.hcum yrev uoy tcepser dna uoy evol I ,hsiF
.sdne yad siht erofeb daed uoy llik lliw I tuB
.
Note that the telnet program is not announcement argument you typed in.
It alone displays the argument accustomed from ReverseEchoer.pl program.
SocketClient.pl - A Simple Atrium Applicant Application
Instead of using the telnet program, we can use the afterward program, SocketClient.pl,
to acquaint with ReverseEchoer.pl:
#- SocketClient.pl
#- Absorb (c) 1999 by Dr. Yang
#
$domain = 2; # Internet domain
$type = 1; # Sequenced, reliable, two-way connection, byte streams
$proto = 6; # Manual Ascendancy Agreement (TCP)
socket(SOCK,$domain,$type,$proto);
$host = pack( C4 , 127,0,0,1); # localhost = 127.0.0.1
$port = 1024;
$address = pack( S n a4 x8 , $domain, $port, $host);
bind(SOCK, $address);
book STDOUT "Client host: ",join( . ,unpack( C4 , $host)),"
";
book STDOUT "Client port: $port
";
$sHost = pack( C4 , 127,0,0,1); # localhost = 127.0.0.1
$sPort = 8888;
$sAddress = pack( S n a4 x8 , $domain, $sPort, $sHost);
connect(SOCK, $sAddress);
book STDOUT "Server host: ",join( . ,unpack( C4 , $sHost)),"
";
book STDOUT "Server port: $sPort
";
select(SOCK); $| = 1; select(STDOUT);
while ($m=<SOCK>) {
$m = <STDIN>;
}
close(SOCK);
exit;
Note that:
- Setting $| to 1 is to about-face on auto even to the absence book handle. In adjustment to
turn on auto even to SOCK, I accept to use select() action to about-face absence file
handles.
Now, run ReverseEchoer.pl, then run SocketClient.pl in a separate command
window. If you blazon in the aforementioned argument as in the antecedent test, you will get
the afterward output:
Client host: 127.0.0.1
Client port: 1024
Server host: 127.0.0.1
Server port: 8888
Welcome to About-face Answer Server.
Fish, I adulation you and account you actual much.
.hcum yrev uoy tcepser dna uoy evol I ,hsiF
But I will annihilate you asleep afore this day ends.
.sdne yad siht erofeb daed uoy llik lliw I tuB
.
Network Account Functions
getprotobyname($protoName) - Allotment the agreement amount of the defined agreement name
in scalar context, and ($protoName,$aliases,$protoNumber) in account context.
getservbyname($serviceName,$protoName) - Allotment the anchorage amount of the specified
network account name and agreement name in scalar context, and
($serviceName,$aliases,$portNumber,$protoName) in account context.
getservbyport($portNumber,$protoName) - Allotment the arrangement account name of the specified
port amount and agreement name in scalar context, and
($serviceName,$aliases,$portNumber,$protoName) in account context.
gethostbyname($hostName) - Allotment the arranged IP abode of the specified
host name in scalar context, and ($name,$aliases,$addrtype,$length,@addrs) in list
context. The host name can aswell be defined in IP abode format.
gethostbyaddr($packedHostAddress) - Allotment the host name of the specified
packed IP abode in scalar context, and ($name,$aliases,$addrtype,$length,@addrs)
in account context.
|
context, stdout, print, protoname, scalar, aliases, protocol, returns, address, domain, server, reverseechoer, program, client, socketclient, socket, servicename, portnumber, telnet, following, shost, select, , scalar context, context and, print stdout, returns the, list context, portnumber protoname, protocol name, protoname returns, aliases portnumber protoname, servicename aliases portnumber, name aliases addrtype, aliases addrtype length, addrtype length @addrs, print stdout server, host join unpack, yad siht erofeb, reverse echo server, siht erofeb daed, uoy llik lliw, print stdout client, dead before this, |
Also see ...
Here is sample program to appearance you how these functions work: NetworkInfo.pm Absorb (c) 1999 by Dr. Yang $s = getprotobyname( tcp ); @l = getprotobyname( tcp ); b
This affiliate describes:Different XML applicant and server advice models.XML and Atrium Advice Archetype GameServer.pl XML and Atrium Advice Archetype GameClient
The bold ID abstraction is acclimated to analyze if an admission XML bulletin is for continuing an absolute bold or starting a new game. If the serverreceives a applicant bulletin for the first time, it will accredit a new bold
This affiliate describes:What is XML RPC?XML RPC specifications.For added advice XSD and XML, see my additional book: " s addendum on XML Tec
From the XML schema, we can see that:A "methodCall" aspect will accept a appropriate "methodName" aspect and an optional"params" element.A "methodName" aspect specifies the name of t
This affiliate describes:Introduction to XML::Simple module.Example Perl programs to use XML::Simple options.Example Perl program to adapt the parsed XML hash.
"forcearray" Archetype XmlSimpleArray.plThe afterward program shows you how to use options, keeproot, searchpath, and forcearray: XmlSimpleArray.pl A
Here is the achievement of the program: Hash dump after suppressempty = :$VAR1 = { arrangement = } ] };XML achievement after suppressempty = :<syst
"keyattr" Archetype XmlSimpleKey.plkeyattr = list: Applies to XMLin() and XMLout() to name attributes, or sub elements as keys to be acclimated to promot the ancestor aspect froma
Notes about "keyattr":Be careful, there is a absence ambience for "keyattr": .If an aspect is begin in the key list, the it s name will be removed,and it s amount will be adapted int