본문 바로가기
조회 수 7612 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print

############
# Server
############

#!/usr/bin/perl -w
#
# Simple RPC server with two methods.
#

use RPC::XML::Server;

# Create the server
my $daemon = RPC::XML::Server->new( host => 'localhost',
                                    port => 8888 );

# Add a simple method
$daemon->add_method({ name => 'hello',
                      signature => ['string'],
                      code => sub {return "Hello world!";} });

# Add another method
$daemon->add_method({ name => 'hellofoo',
                      signature => ['string string'],
                      code => \&helloFoo });

# Start the server up.
$daemon->server_loop();

# The function called when a request for 'hellofoo' is made.
sub helloFoo
{
    my( $srv, $name ) = ( @_ );

    return( "Hello $name" );
}

############
# Client
############

#!/usr/bin/perl -w

use strict;
require RPC::XML;
require RPC::XML::Client;

my $client = RPC::XML::Client->new('http://localhost:8888');

#
#  Call our hello function with no arguments.
#
#  Print the response
#
my $res = $client->send_request('hello');
print "(hello) - Response: " . $res->value . "\n";

#
#  Now call our "Hello Foo"
#
my $req = RPC::XML::request->new('hellofoo',
                                 RPC::XML::string->new('Steve'));
$res = $client->send_request($req);
print "(hellofoo 'Steve') - Response value = " . $res->value . "\n";

######################
# Test from client
######################

$ ./rpc_client.pl 
(hello) - Response: Hello world!
(hellofoo 'Steve') - Response value = Hello Steve

################
# from client
################

POST / HTTP/1.1
TE: deflate,gzip;q=0.3
Connection: TE, close
Accept-Encoding: deflate
Host: localhost
User-Agent: RPC::XML::Client/1.39 libwww-perl/5.837
Content-Length: 113
Content-Type: text/xml

<?xml version="1.0" encoding="us-ascii"?><methodCall><methodName>hello</methodName><params></params></methodCall>

################
# from server
################

HTTP/1.1 200 OK
Date: Wed, 30 May 2012 08:59:56 GMT
Server: libwww-perl-daemon/5.827
Accept: text/xml
Accept-Encoding: deflate
Content-Length: 150
Content-Type: text/xml
RPC-Encoding: XML-RPC
RPC-Server: RPC::XML::Server/1.68

<?xml version="1.0" encoding="us-ascii"?><methodResponse><params><param><value><string>Hello world!</string></value></param></params></methodResponse>

---------------------------------------------------------------

POST / HTTP/1.1
TE: deflate,gzip;q=0.3
Connection: TE, close
Accept-Encoding: deflate
Host: localhost
User-Agent: RPC::XML::Client/1.39 libwww-perl/5.837
Content-Length: 168
Content-Type: text/xml

<?xml version="1.0" encoding="us-ascii"?><methodCall><methodName>hellofoo</methodName><params><param><value><string>Steve</string></value></param></params></methodCall>

HTTP/1.1 200 OK
Date: Wed, 30 May 2012 08:59:56 GMT
Server: libwww-perl-daemon/5.827
Accept: text/xml
Accept-Encoding: deflate
Content-Length: 149
Content-Type: text/xml
RPC-Encoding: XML-RPC
RPC-Server: RPC::XML::Server/1.68

<?xml version="1.0" encoding="us-ascii"?><methodResponse><params><param><value><string>Hello Steve</string></value></param></params></methodResponse>



Title
List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
공지 기본정보 Regular Expression Reference Hojung 2012.12.03 20717
공지 기본정보 모듈 설치방법 Hojung 2012.10.31 17732
공지 기본정보 Activestate 설치 + PATH 설정 + 모듈 설치 Hojung 2010.04.19 35983
64 예제코드 Perl script to push samples to Virustotal Hojung 2014.02.20 5830
63 예제코드 TS 디렉토리에서 techsupport 찾아 모델별로 mv 명령 출력 (File::Find) Hojung 2013.01.22 8238
62 예제코드 How can I read in an entire file all at once?: Hojung 2013.01.14 8812
61 예제코드 Perl Expect ssh and scp example script Hojung 2012.12.23 12088
60 기본정보 How to install HTML::HTMLDoc from Mac Hojung 2012.11.19 8004
59 기본정보 How to install module (모듈 설치방법 3가지) Hojung 2012.11.19 7754
58 기본정보 How to uninstall module from CPAN Hojung 2012.11.19 7933
57 예제코드 turning seconds into days, hours, minutes and seconds Hojung 2012.11.12 7658
56 예제코드 How to print Unix timestamp Hojung 2012.11.12 9430
55 기본정보 MAC에서 HTML::HTMLDoc 설치하기 Hojung 2012.10.31 8270
54 기본정보 Mac에서 PDF::FromHTML 모듈 설치하기 Hojung 2012.10.31 7969
53 기본정보 CPAN: Automatically install dependencies without confirmation Hojung 2012.10.31 8798
52 예제코드 WWW::Mechanize::Firefox file Hojung 2012.10.30 9846
51 예제코드 Get number of elements in an array and a hash Hojung 2012.06.04 7250
» 예제코드 Cross-platform cross-environment RPC server creation Hojung 2012.05.30 7612
49 예제코드 인수가 이메일형식인지 확인 Hojung 2012.03.11 7881
48 예제코드 How to keep session in Perl CGI Hojung 2012.03.07 7811
47 기본정보 CGI::Session::Tutorial Hojung 2012.03.06 8165
Board Pagination ‹ Prev 1 2 3 4 Next ›
/ 4

Designed by sketchbooks.co.kr / sketchbook5 board skin

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5