⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 faq.html

📁 this gives details of the network programming
💻 HTML
字号:
<HTML><HEAD><TITLE>NetProg Homework 7 FAQ</TITLE><LINK rel=stylesheet type="text/css" HREF=../../style/proj.css></HEAD><BODY BGCOLOR=WHITE MARGINHEIGHT=0 MARGINWIDTH=0 TOPMARGIN=0  LEFTMARGIN=0><TABLE bgColor=#8899aa border=0 cellPadding=4 cellSpacing=0 width="100%">  <TR>    <TD class=title>&nbsp NetProg 2002 HW7 FAQ</TD> </TR><TR BGCOLOR=BLACK><TD CLASS=menu> &nbsp &nbsp<A CLASS=menu HREF=7.html>Proj. Desc.</A> &nbsp &nbsp |&nbsp &nbsp<A CLASS=menu HREF=../submission.html>Submitting</A>&nbsp &nbsp |&nbsp &nbsp<A CLASS=menu HREF=#rmireg>rmiregistry trouble</A> &nbsp &nbsp |&nbsp &nbsp<A CLASS=menu HREF=#serial>Serializable Exceptions</A> &nbsp &nbsp | &nbsp &nbsp<A CLASS=menu HREF=#rpc>RPC-Howto </A> &nbsp &nbsp |&nbsp &nbsp<A CLASS=menu HREF=#rmi>RMI-Howto </A></TD></TR></TABLE><BR><BR><DIV CLASS=page><CENTER><TABLE WIDTH=90% CELLPADDING=3 BORDER=0 CELLSPACING=0><TR BGCOLOR=#ddeeff>  <TD VALIGN=TOP CLASS=label>Question:</TD>  <TD CLASS=qa><P><A NAME=rmireg>I'm having trouble with the rmiregistry, it won't  seem to run!</A> </P></TD></TR><TR BGCOLOR=#ffeedd>  <TD VALIGN=TOP CLASS=label>Answer:</TD>  <TD CLASS=qa><P>Chances are that someone else is running it on the  default port. You can run your own copy on whatever port you want  (just specify a port number on the command line), but you need to  include a port number in the rmi URLS in both your client and server  (that you give to <CODE>Naming.bind()</CODE> and  <CODE>Naming.lookup()</CODE>). In the server you can use a URL like  <CODE>"//:8765/Objname"</CODE> to specify the port, (with no  hostname it is assumes you want the local host).  </P>  <P>There is a complete RMI  example that supports having the  registry tun on an alternate port here:  <A  HREF=../../code/java/SimpleRMIport/default.htm>  <CODE>http://monte.cs.rpi.edu/~hollingd/netprog/code/java/SimpleRMIport/</CODE></A> </P></TD></TR><TR><TD COLSPAN=2><BR> <HR WIDTH=80%><BR></TD></TR><TR BGCOLOR=#ddeeff>  <TD VALIGN=TOP CLASS=label>Question:</TD>  <TD CLASS=qa><P><A NAME=serial></A>I get a runtime error when I call  a remote method that creates an object I've defined to hold the  components of a URL. The error message says that my class is not  "serializable", how do I fix this? </P></TD></TR><TR BGCOLOR=#ffeedd>  <TD VALIGN=TOP CLASS=label>Answer:</TD>  <TD CLASS=qa><P>If you want to send (as a parameter) or receive (as  a return value) an object whose class you have defined, your class  must implement the interface "Serializable". Note that unless you  are doing something tricky, you can do this by simply declaring that  the class "implements Serializable", no additional code is  necessary. The interface <CODE>Serializable</CODE> is in java.io, so  you need to <CODE>import java.io.*</CODE>. </P> <P>You can also wait and try again later, or move to a different machine...</P></TD></TR><TR><TD COLSPAN=2><BR> <HR WIDTH=80%><BR></TD></TR><TR BGCOLOR=#ddeeff>  <TD VALIGN=TOP CLASS=label>Question:</TD>  <TD CLASS=qa><P><A NAME=rpc>I want to use RPC, how do I get started?</A> </P></TD></TR><TR BGCOLOR=#ffeedd>  <TD VALIGN=TOP CLASS=label>Answer:</TD>  <TD CLASS=qa>   <P><B>Step 1:</B> First write and debug a program that can parse  and build URLs. Don't worry about RPC until you have this part  done.</P>  <P><B>Step 2:</B> Develop a protocol definition file (a   <CODE>.x</CODE> file) that includes declarations for 2 remote  procedures, one should return a string and accept a structure  that includes fields for each component of a URL, the other should  accept a string and return a structure. You need to define  the structure in the protocol definition file as well.</P>  <P><B>Step 3:</B> Run <CODE>rpcgen -C</CODE> on your protocol  definition file. If you file is named <CODE>hw7.x</CODE>, you need  to run: <CODE>rpcgen -C hw7.x</CODE>.</P>  <P><B>Step 4:</B> Look at the <CODE>.h</CODE> file generated by  rpcgen (the name will be the same name as your protocol definition  file). Here you will see what your structure looks like as a C data  structure and the prototypes for the functions your client will  call.</P>  <P><B>Step 5:</B> Make a copy of the program you developed in step  1 that will become your client (name it hw7client.c or something  like that). You need to add some RPC  initializtion stuff to the <CODE>main()</CODE>, something like  this (which assumes the hostname of the server comes from argv[1]):</P>  <CENTER><TABLE WIDTH=60% BGCOLOR=CYAN><TR><TD>  <PRE> CLIENT *clnt; clnt = clnt_create(argv[1], HW7_PROG, HW7_VERSION, "udp"); </PRE> </TD></TR></TABLE></CENTER> <P>Note that <CODE>HW7_PROG</CODE> and <CODE>HW7_VERSION</CODE> must match whatever you specified in your <CODE>.x</CODE> file.</P>  <P><B>Step 6:</B> Change the rest of the client program so that it calls the client stubs instead of your actual functions (which you should remove from the client). </P> <P><B>Step 7:</B> Run <CODE>rpcgen -C -Ss hw7.x > hw7service.c</CODE>, this will create a dummy server file. Edit this file, changing the code inside each of the remote procedures created for you so that they include the actual code (the code you removed from the client in step 6). You probably need to do a little work matching up data types, etc.</P> <P><B>Step 8:</B> Build the client, probably something like this:</P> <PRE>  gcc -o client hw7client.c hw7_clnt.c hw7_xdr.c -lnsl </PRE>  <P>Build the server:</P>  <PRE>  gcc -DRPC_SVC_FG  -o server hw7service.c hw7_svc.c hw7_xdr.c -lrpcsvc -lnsl  </PRE>  <P>Note: -DRPC_SVC_FG will force your server to run in the  foreground, if you don't add this it will become a daemon (and it  will be harder to debug and test).</P> <P><B>Step 9: </B>Run the server, run the client to test everything.</P> <P><B>Step 10:</B> Make sure you don't forget to write up detailed instructions on how we should build and test your program. Include a few sample command lines for the client. Submit your project, andstart studying for the Netprog comprehensive final exam that will take place every day of finals week from 6AM-9AM in the Gym. Make sure your sneakers are in good shape, you have protective eye gear, and that have bring plenty of GatorAde to bring to the final.</P><DIV CLASS=in STYLE="font-size: 8pt">This is a joke, there is nocomprehensive final exam, just test #2 on the last day of class</DIV></DIV> </P></TD></TR><TR><TD COLSPAN=2><BR> <HR WIDTH=80%><BR></TD></TR><TR BGCOLOR=#ddeeff>  <TD VALIGN=TOP CLASS=label>Question:</TD>  <TD CLASS=qa><P><A NAME=rmi>I want to use RMI, how do I get started?</A> </P></TD></TR><TR BGCOLOR=#ffeedd>  <TD VALIGN=TOP CLASS=label>Answer:</TD>  <TD CLASS=qa>  <P><B>Step 1.</B> Write and debug a Java program (a class with a  <CODE>main()</CODE>) that supports the operations  requested. Although you can use a Java URL object to do the work,  you need to write your own class (you need to write some code!).</P>  <P><B>Step 2.</B> Create an <CODE>interface</code> that extends   <CODE>java.rmi.Remote</CODE> and includes the 2 methods you need to  support (one that parses urls, the other constructs urls). Make sure  you declare that each of the methods throws <CODE>RemoteException</CODE>. </P> <P><B>Step 3.</B> Create a <CODE>class</CODE> that implements your  <CODE>interface</CODE> (that you created in step 2) and extends the class <CODE>java.rmi.server.UnicastRemoteObject</CODE>. The code for  each method you define here can be taken from the class you developed  in step 1. You should include a constructor that calls <CODE>super()</CODE> (this calls the constuctor for <CODE>UnicastRemoteObject</CODE>). You can also turn this into a server program by including a <CODE>main()</CODE> that creates an object and registers it with the naming service. Check the sample code for an example. </P> <P><B>Step 4.</B> Compile your interface (step 2) and class (step 3). Now run <CODE>rmic</CODE> and give it the name of your class (step 2). This will generate the client stubs and server skeleton classes. </P> <P><B>Step 5.</B> Write a class that will act as a client to test your remote object. Most of this can come from the code your wrote in step 1. To use a remote object you need to ask the naming service for a remote object reference, then cast that object to an object of type that supports your interface (defined in step 2). Check one of the samples for the details. </P>  <P><B>Step 6.</B> Start up the rmi registry with the command  <CODE>rmiregistry</CODE>. If the registry won't run, chances are  someone else is running it on the same machine - see the top  question in the FAQ for info on how to run yours on an alternate  port.</P> <P><B>Step 7.</B> Start up your server (the class created in step 3),  and test with your client (created in step 5).</P> <P><B>NOTE:</B> If any of your remote methods return an object, the object must be <em>serializable</em> (or it won't work with RMI). You need to have the class definition for the object type returned <CODE>implement java.io.Serializable</CODE></P> </TD></TR><TR><TD COLSPAN=2><BR> <HR WIDTH=80%><BR></TD></TR><!--<TR><TD COLSPAN=2><BR> <HR WIDTH=80%><BR></TD></TR><TR BGCOLOR=#ddeeff>  <TD VALIGN=TOP CLASS=label>Question:</TD>  <TD CLASS=qa><P> </P></TD></TR><TR BGCOLOR=#ffeedd>  <TD VALIGN=TOP CLASS=label>Answer:</TD>  <TD CLASS=qa><P> </P></TD></TR><TR><TD COLSPAN=2><BR> <HR WIDTH=80%><BR></TD></TR>--></TABLE>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -