Article View: fj.sys.sun
Article #13234Using rpc on xview library.
From: Junsei Sugino
Date: Mon, 30 Nov 1992 13:04
Date: Mon, 30 Nov 1992 13:04
229 lines
6635 bytes
6635 bytes
$@$3$s$K$A$O!"?yLn!wF|K\%f%K%7%9$G$9!#(J
$@$$$^!"(Jrpc $@$r;H$C$?%W%m%0%i%`$r=q$3$&$H$7$F$$$k(J$@$N$G$9$,(J xview $@$H$&$^$/(J
$@6&B8$5$;$k$3$H$,=PMh$:$K:$$C$F$$$^$9!#(J
$@%W%m%0%i%`$OC1=c$G!"<!$h$&$J$b$N$G$9!#(J
1) main ($@%5!<%P(J)
$@!&(Jxv_init() $@$9$k!#(J
$@!&(Jsvc_register() $@$G4X?t$rEPO?$9$k!#(J
$@!&(Jnotify_set_input_func() $@$GBP1~$9$k(J socket $@$r(J xview $@$K65$($k!#(J
$@!&(Jxv_main_loop() $@$KF~$k!#(J
2) clnt ($@%/%i%$%"%s%H(J)
$@!&(Jclnt_create() $@$G%/%i%$%"%s%H:n$k!#(J
$@!&%5!<%P$r8F$S=P$9!#(J
$@$$$m$$$m%G%P%C%/%W%j%s%H$r$7$?7k2L!"(Jnotify_set_input_func() $@$GEPO?$7$?(J
$@4X?t$O8F$S=P$5$l$k$N$G$9$,!"$=$NCf$G8F$s$G$$$k(J svc_getreqset() $@$,(J
messageprog_1() $@$r8F$S=P$9$O$:$J$N$K!"A4$/8F$S=P$5$l$^$;$s!#(J
$@$J$s$H$J$/(J xview $@$,%j%i%$%H$7$F$$$k(J read/write $@$,0-$5(J$@$r$7$F$$$k$h$&$J(J
$@5$$,$9$k$N$G$9$,!"!"!"$h$/$o$+$j$^$;$s!#(J
$@%R%s%H$G7k9=$G$9$+$i!"65$($F2<$5$$!#(J
$@$A$J(J$@$_$K!"EvJ}$N4D6-$O(J
Sparc Station 2
SunOS 4.1.1 (JLE 1.1.1)
OpenWindows 2.0.1 Rev.C (Patch $@$J$7(J)
$@$G(J$@$9!#(J
$@%W%m%0%i%`$O0J2<$NDL$j$G$9!#$h$m$7$/$*4j$$$7$^$9!#(J
------------------------ main.c (start) ------------------------
#include <locale.h>
#include <xview/xview.h>
#include <xview/panel.h>
#include <rpc/rpc.h>
#include <rpc/svc.h>
#include "msg.h"
static Xv_Server xv_server;
static Panel_item item1;
int* printmessage_1( msg )
char** msg;
{
static result = 1; /* must be static */
fprintf( stderr, "printmessage_1(%s)\n", *msg );
xv_set( item1, PANEL_VALUE, *msg, NULL );
return &result;
}
Frame setting_xview() /* xview programs */
{
Frame frame;
Panel panel;
Panel_item item1;
frame = xv_create( NULL, FRAME,
XV_WIDTH, 300,
XV_HEIGHT, 150,
NULL );
panel = xv_create( frame, PANEL,
XV_WIDTH, 300,
XV_HEIGHT, 150,
NULL );
item1 = xv_create( panel, PANEL_TEXT,
PANEL_LABEL_STRING, "DATA 1",
PANEL_CLIENT_DATA, 1,
NULL );
xv_set( frame, XV_SHOW, TRUE, NULL );
return frame;
}
void messageprog_1();
static Notify_value
fire_rpc( client, fd )
int* client;
int fd;
{
int i;
fd_set my_fd_set;
fprintf( stderr, "fire_rpc(%d)\n", fd );
FD_ZERO( &my_fd_set );
FD_SET( fd, &my_fd_set );
svc_getreqset( &my_fd_set );
return NOTIFY_DONE;
}
void setting_rpc() /* rpc programs */
{
SVCXPRT *transp;
int i;
static int client;
(void) pmap_unset(MESSAGEPROG, MESSAGEVERS);
transp = svcudp_create(RPC_ANYSOCK);
if (transp == NULL) {
fprintf(stderr, "cannot create udp service.");
exit(1);
}
if (!svc_register(transp, MESSAGEPROG, MESSAGEVERS, messageprog_1, IPPROTO_UDP)) {
fprintf(stderr, "unable to register (MESSAGEPROG, MESSAGEVERS, udp).");
exit(1);
}
transp = svctcp_create(RPC_ANYSOCK, 0, 0);
if (transp == NULL) {
fprintf(stderr, "cannot create tcp service.");
exit(1);
}
if (!svc_register(transp, MESSAGEPROG, MESSAGEVERS, messageprog_1, IPPROTO_TCP)) {
fprintf(stderr, "unable to register (MESSAGEPROG, MESSAGEVERS, tcp).");
exit(1);
}
for ( i = 0; i < FD_SETSIZE; ++i ) {
if ( FD_ISSET(i,&svc_fdset) ) {
fprintf( stderr, "setting fd(%d)\n", i );
notify_set_input_func( &client, fire_rpc, i );
}
}
}
int main( argc, argv )
int argc;
char* argv[];
{
Frame frame;
setlocale( LC_CTYPE, "" );
xv_server = xv_init(XV_USE_LOCALE, TRUE, XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
frame = setting_xview();
setting_rpc();
xv_main_loop(frame);
}
------------------------ main.c (end) ------------------------
------------------------ clnt.c (start) ------------------------
#include <stdio.h>
#include <rpc/rpc.h>
#include "msg.h"
int main(argc,argv)
int argc;
char* argv[];
{
CLIENT* cl;
int* result;
char* server;
char* message;
if ( argc != 3 ) {
fprintf( stderr,
"usage : %s host message\n", argv[0] );
exit(1);
}
server = argv[1];
message = argv[2];
cl = clnt_create( server, MESSAGEPROG, MESSAGEVERS, "tcp");
if ( cl == NULL ) {
clnt_pcreateerror(server);
return 1;
}
result = printmessage_1( &message, cl );
if ( result == NULL ) {
clnt_perror( cl, server );
return 1;
}
if ( *result == 0 ) {
fprintf(stderr, "%s : %s couldn't print your messge\n", argv[0], server );
}
printf( "mseeage deliverd to %s!\n", server );
return 0;
}
------------------------ clnt.c (end) ------------------------
------------------------ msg.x (start) ------------------------
program MESSAGEPROG {
version MESSAGEVERS {
int PRINTMESSAGE(string) = 1;
} = 1;
} = 99;
------------------------ msg.x (end) ------------------------
------------------------ Makefile (start) ------------------------
CPPFLAGS=-I/usr/openwin/include -DOW_I18N
LDFLAGS=-L/usr/openwin/lib
LDLIBS = -ll -ljapanese -lm -lxview -lolgx -lmle -lX11
all: main clnt
main: main.o msg_svc.o
$(LINK.c) -o main main.o msg_svc.o $(LDLIBS)
clnt: clnt.c msg_clnt.o
$(LINK.c) -o clnt clnt.c msg_clnt.o $(LDLIBS)
main.o msg_svc.o clnt.o msg_clnt.o: msg.h
msg_svc.c: msg.x
rpcgen -m -o msg_svc.c msg.x
msg_clnt.c: msg.x
rpcgen -l -o msg_clnt.c msg.x
msg.h: msg.x
rpcgen -h -o msg.h msg.x
distclean: clean
rm -f main
rm -f clnt
clean:
rm -f *.o
rm -f msg_svc.c
rm -f msg_clnt.c
rm -f msg.h
------------------------ Makefile (end) ------------------------
--
$@?yLn=g@6(J (Junsei Sugino)
$@F|K\%f%K%7%9(J($@3t(J) $@CN<1%7%9%F%`(J$@It(J $@3+H/5;=Q2](J
(Nihon Unisys co. Knowledge Systems Development Technology)
TEL 03-5562-1213 FAX 03-5562-1299
(TEL +81-3-5562-1213 FAX +81-3-5562-1299)
Technical Details
Message-ID:
<SUGINO.92Nov30220448@mars.tippler.unisys.co.jp>Path:
arc1-ca.pugleaf.net!sparky!uunet!ccut!wnoc-tyo-news!unisysgw!tippler!tippler.unisys.co.jp!suginoShow Full Headers
Complete Article Headers
X-Google-Language: Japanese,JIS X-Google-Thread: fcfb5,ba2eb0313828c87a,start X-Google-Attributes: gidfcfb5,public X-Google-ArrivalTime: 1992-11-30 05:23:29 PST Newsgroups: fj.sys.sun Path: arc1-ca.pugleaf.net!sparky!uunet!ccut!wnoc-tyo-news!unisysgw!tippler!tippler.unisys.co.jp!sugino From: sugino@tippler.unisys.co.jp (Junsei Sugino) Subject: Using rpc on xview library. Message-ID: <SUGINO.92Nov30220448@mars.tippler.unisys.co.jp> Sender: news@tippler.unisys.co.jp Nntp-Posting-Host: mars.tippler.unisys.co.jp Reply-To: sugino@tippler.unisys.co.jp Organization: NIHON UNISYS, Ltd. Distribution: fj Date: Mon, 30 Nov 1992 13:04:48 GMT Lines: 229