孤独不哭(苦)'s profile孤独不哭(苦)的共享空间PhotosBlogListsMore Tools Help

Blog


    November 24

    Internet Communications Engine ---3

     前面的代码都是例行公事,public class PrinterI : _PrinterDisp的代码才是我们需要的(简单吧!)
        按照同样的方法,我们建立IceClientTest项目,先添加Printer.cs文件,然后编写Cient.cs文件,具体内容如下:
    using System;

    namespace IceClientTest
    {
        
    /**//// <summary>
        
    /// Summary description for Client.
        
    /// </summary>

        public class Client
        
    {
            
    public Client()
            
    {
                
    //
                
    // TODO: Add constructor logic here
                
    //
            }


            
    public static void Main(string[] args)
            
    {
                
    int status = 0;
                Ice.Communicator ic 
    = null;
                
    try 
                
    {
                    ic 
    = Ice.Util.initialize(ref args);
                    Ice.ObjectPrx obj 
    = ic.stringToProxy(
                        
    "SimplePrinter:default -p 10000");
                    PrinterPrx printer
                        
    = PrinterPrxHelper.checkedCast(obj);
                    
    if (printer == null)
                        
    throw new ApplicationException("Invalid proxy");
                    printer.printString(
    "Hello World!");
                }
     
                
    catch (Exception e) 
                
    {
                    Console.Error.WriteLine(e);
                    status 
    = 1;
                }
     
                
    finally 
                
    {
                    
    if (ic != null)
                        ic.destroy();
                }

                Environment.Exit(status);
            }

        }

    }


        同样,里面大部分都是例行公事,只有printer.printString("Hello World!");一句才是关键。
        现在我们可以Build解决方案了,成功后便产生了IceTest.exe 和IceClientTest.exe 文件。如果没有成功,记得在项目中添加引用,加入icecs.dll(也在安装的bin目录下)。
        应该可以了,下面看看运行结果:


        运行结果很简单,就是服务端输出客户端输入的“Hello World”字符串。比Corba简单吧?
        最后贴出服务端的UML图,客户端的类似就不贴了。


        以上是我参考《Distributed Programming with Ice》(官方网站可以下载,是Ice软件包的官方文档)一书做的练习,内容很简单,请大家指教!

    我这里还有中文版的说明文档,感兴趣的朋友研究一下,交流交流--------

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://gudulone.spaces.live.com/blog/cns!6C30ED9B5F4F38F1!119.trak
    Weblogs that reference this entry
    • None