[Portal] with Ruby call ICE interface

Ice is not introduced, http://www.zeroc.com/
Ruby is not introduced.

I try ah, the steps I will be clearly recorded,
One to definitely not let the people Society,
Second, I am afraid I have forgotten the past two days, brain hypoxia, only three days to remember things. . . . . .

Download Ice-3.3.0-VC60.msi

http://www.zeroc.com/download/Ice/3.3/Ice-3.3.0-VC60.msi

ICE From the outset 3.1.1 Supporting the Ruby dynamic language also supports Python, php.

After the download to install, skip.

After installation, please open the installation directory, read the "README.txt", if you feel too tired to read in English do not want to detours, then please carefully read this blog.

First of all, Ice3.3.0 support Ruby is 1.8.6, please confirm.
Secondly, README.txt in and said:

Quote

"You also need to add the Ice bin directory to your PATH, for example:

set PATH = <Ice installation root directory> \ bin;% PATH%

Finally, set RUBYLIB so that the Ruby interpreter is able to load
the Ice extension:

set RUBYLIB = <Ice installation root directory> \ ruby;% RUBYLIB% "

So please in your environment variables to set / increase the above two, do not wrong! ! !

Environment variables you get? Get your IRB try out,

win+r->cmd->irb:
require 'rubygems'
require 'Ice'

Require the implementation of these two after if successful, then congratulations to you, Ice the ruby work environment has been done.

Ice how the job I do not want to go on, Service After the development of client interfaces, using. Ice documents describe interfaces and data formats, and then this. Ice document to the client, the client can go into slice2 **** the appropriate language interface file, loading into account and can use server-side interface and good agreement data.

This article mainly refers to the client how to use ruby invoke server-side interfaces, server-side so we will realize no matter how I put the main server-side code give everyone a look everyone will understand, better than everybody smart Oh my!

The following services are the main client code,

/* This code is to start the Ice, the routine of things  */
	Ice::ObjectAdapterPtr adapter = ic->createObjectAdapterWithEndpoints("WGSrv","default -p 7788");
// The server port is 7788
	Ice::ObjectPtr object = new CTestIceImpl();
	adapter->add(object, ic->stringToIdentity("WGInterfaceAgentId"));
	// This is important, the Convention with a card as the client, is used to determine the client calls the server of which ice interface.
	adapter->activate();

	std::cout << "now server start successfully." << std::endl;

	ic->waitForShutdown();
/* This code is server-side interface implementation,
* I choose a ping interface for everyone to see,
* We can see this ping in addition to the Terminal  ( Server-side  ) Output  "ping successfully." This string,
* A 0 is returned, not doing anything other than that, very simple.
*/
	int ping(const Ice::Current& = Ice::Current())
	{
		std::cout << "ping successfully." << std::endl;
		return 0;
	}

Above are server things, the following are to visit the Ruby interface methods:

<<COMMENT
 There's something almost all of the routine, you need to implement the code please put somewhere else, you need to load in.
COMMENT
require 'Ice'
Ice::loadSlice('testice.ice')# The service side to your  .ice Here!  

status = 0
ic = nil
begin
    ic = Ice::initialize(ARGV)
    base = ic.stringToProxy("WGInterfaceAgentId:default -p 7788 -h 10.2.226.8")
# The preceding sentence, please note that server-side one of the words "adapter  ->add(object, ic->stringToIdentity("WGInterfaceAgentId")); ”
# We mentioned above  "WGInterfaceAgentId" This string is used to identify the destination interface, now with oh.
    pinger = WG::WGTestIcePrx::checkedCast(base)
    if not pinger
        raise "Invalid proxy"
    end

    pinger.ping()# Only the most useful, others are routine.
rescue
    puts $!
    puts $!.backtrace.join("\n")
    status = 1
end

if ic
    # Clean up
    begin
        ic.destroy()
    rescue
        puts $!
        puts $!.backtrace.join("\n")
        status = 1
    end
end

exit(status)

Executive about the success.

I did not carefully studied the ICE, there has never been used before this thing, This is the first time, read the documentation under the ZeroC, ask a friend, to complete the call, but there do not understand my problem, Ice provides a tools are slice2 ****, this tool for the static language is used to convert. ice documents to each other's language, but I use dynamic languages such as Ruby interface to call Ice, I found that even if I put the generated files slice2rb document also does not matter deleted, the same call through, I think this may be the use of dynamic languages without a statement of the characteristics of the definition of it, it seems to use Ruby to call Ice interface is too convenient! !

Pro, and would like to thank my buddies: Student crown, Ice Service client interfaces that are easy to write of him.

Had finished.

分类:Ruby 时间:2009-03-07 人气:874
分享到:
blog comments powered by Disqus

相关文章

  • java environment variables configuration summary 2010-03-29

    windows xp configure JDK environment variables: 1. Install JDK, the installation process you can customize the installation directory and other information, for example, we have chosen to install directory is D: \ java \ jdk1.5.0_08; 2. The installat

  • linux install JDK, and configure the environment variables 2010-09-07

    A: install 1: The first line of the JDK under a linux version. Eg: jdk-1_5_0_06-linux-i586-rpm.bin 2: then put into a directory of recommended / usr directory and then in the construction of a directory java, to put it inside the next version 3: just

  • VFS + SFTP root directory redirection 2010-06-09

    In order to project requirements SFTP helpless on the floor of the Apache in the VFS. Online introduction to the VFS few official DOC can be ignored. Found no SFTP access to the root directory where to begin debugging VFS. Finally resolved the issue

  • ubuntu install jdk, ubuntu set java environment variables 2011-07-05

    ubuntu install jdk, ubuntu set java environment variables, ubuntu install jdk, ubuntu set java environment variables, ubuntu install jdk, ubuntu set java environment variables Download jdk-6u12-linux-i586.bin, To install jdk: Use the terminal to ente

  • How to read a user's crontab environment variables in parameters 2010-04-27

    How to read a user's crontab environment variables in parameters We all know that crontab is good stuff, you can perform some tasks regularly to help you monitor system status, to help you every day to do some mechanical things. However, there is cro

  • Set the Apache HTTP Server document root directory (DocumentRoot) 2010-09-29

    Set the Apache HTTP Server document root directory (DocumentRoot). Apache is installed, the system will set a default document root directory. If you think there is the default directory the page is not convenient, think we should also set up a direc

  • Ruby environment variables 2010-02-02

    Ruby installation environment variables Ruby in the installation process will automatically modify the system environment variable PATH, and add the environment variable RUBYOPT (So do not need to configure the Ruby environment variables, this is a v

  • Start the installation of Ruby articles 2010-12-12

    Introduction: ^ _ ^ ^ _ ^ have a personal profile on the pre-shot the familiar banner of Ruby, but I now began to formally learn Ruby. The installation of Ruby 1, to the official website to download http://www.ruby-lang.org/en/downloads/ I downloaded

  • Under linux set environment variables at startup and software installation 2010-12-23

    1, set the startup environment variables from the configuration In the Linux terminal environment, export command can be used to set environment variables, but it set the variable disappears immediately after you close the terminal. If you want to se

  • under linux set environment variables and start the software installation 2010-12-23

    1, set the startup environment variables from the configuration Terminal in Linux environment, export command can be used to set environment variables, but it set the variables disappear immediately after you close the terminal. If you want to set it

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.527 (s). 12 q(s)