金正nontaus液晶电视:使用C#编写Zeroc?ICE应用程序的例子
来源:百度文库 编辑:九乡新闻网 时间:2024/05/03 06:25:07
使用C#编写Zeroc ICE应用程序的例子
Internet Communications Engine (Ice)是现代面向对象的中间件,它支持C++, C#, Java, Python, Ruby, PHP, 和 VisualBasic开发语言。ZerocICE中间件号称标准统一,开源,跨平台,跨语言,分布式,安全,服务透明,负载均衡,面向对象,性能优越,防火期穿透,通讯屏蔽。因此相比Corba,DCOM,SOAP,J2EE等的中间件技术,自然是集众多优点于一身,而且他简单易学。Ice是一个自由软件,所有代码都可用,是在GNUGeneral Public License (GPL)下发布的。
这里.服务端和客户端都使用VS.NET 2005开发,语言采用C#,
1,安装ice,这里安装在D:\Lib\Ice-3.3.0
2,编写DemoIce.ice文件,
// **********************************************************************
// Copyright (c) 2003-2008 ZhangEF, Inc. All rights reserved.
// **********************************************************************
#ifndef DEMO_ICE
#define DEMO_ICE
module Demo
{
enum DemoEnum
{
G722,
G726,
};
struct DemoStruct
{
int nValue;
string strValue;
DemoEnum eValue;
};
interface DemoIce
{
idempotent void SetEx(int nId, DemoStruct param);
["cpp:const"] idempotent void GetEx(int nId, out DemoStruct param);
};
}; //end module
#endif
3,编译成DemoIce.cs文件
path D:\Lib\Ice-3.3.0\bin
slice2cs.exe IceDemo.ice
4,创建.net2005 控制台项目添加现有项目 DemoIce.cs文件,添加引用 [ICE]\bin\Ice.dll
5,在服务断代码里实现抽象类的所有接口,抽象类在DemoIce.cs文件中,以Disp_结尾.
6,服务器端代码:
using System;
using System.Collections.Generic;
using System.Text;
using Demo;
using System.Reflection;
namespace IceServerCon
{
public class DemoIceI : DemoIceDisp_
{
DemoStruct m_data = new DemoStruct();
public override void GetEx(int nId, out DemoStruct param, Ice.Current current__)
{
param = m_data;
Console.WriteLine("GetEx() called");
}
public override void SetEx(int nId, DemoStruct param, Ice.Current current__)
{
m_data = param;
Console.WriteLine("SetEx() called");
}
}
class Program
{
static void Main(string[] args)
{
try
{
int status = 0;
Ice.Communicator ic = null;
try
{
ic = Ice.Util.initialize(ref args);
Ice.ObjectAdapter adapter = ic.createObjectAdapterWithEndpoints("DemoIce", "default -p 10000");
Ice.Object obj = new DemoIceI();
adapter.add(obj, ic.stringToIdentity("DemoIce"));
adapter.activate();
//ic.waitForShutdown();
}
catch (Exception e)
{
Console.Error.WriteLine(e);
status = 1;
}
Console.WriteLine("Server Start [OK]");
Console.ReadLine();
if (ic != null)
{
try
{
ic.destroy();
}
catch (Exception e)
{
Console.Error.WriteLine(e);
status = 1;
}
}
if (status != 0)
{
System.Environment.Exit(status);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
7,客户端代码
using System;
using System.Collections.Generic;
using System.Text;
using Demo;
namespace IceClientCon
{
class Program
{
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("DemoIce:tcp -h127.0.0.1 -p 10000").ice_twoway().ice_timeout(200).ice_secure(false);
DemoIcePrx demoIce = DemoIcePrxHelper.checkedCast(obj);
if (demoIce == null)
throw new ApplicationException("Invalid proxy");
DemoStruct data1 = new DemoStruct();
DemoStruct data2 ;
data1.strValue = "Hellow Server";
demoIce.SetEx(1, data1);
demoIce.GetEx(1, out data2);
Console.WriteLine("data2.strValue = {0}", data2.strValue);
}
catch (Exception e)
{
Console.Error.WriteLine(e);
status = 1;
}
Console.ReadLine();
if (ic != null)
{
try
{
ic.destroy();
}
catch (Exception e)
{
Console.Error.WriteLine(e);
status = 1;
}
}
if (status != 0)
{
System.Environment.Exit(status);
}
}
}
}
Internet Communications Engine (Ice)是现代面向对象的中间件,它支持C++, C#, Java, Python, Ruby, PHP, 和 VisualBasic开发语言。ZerocICE中间件号称标准统一,开源,跨平台,跨语言,分布式,安全,服务透明,负载均衡,面向对象,性能优越,防火期穿透,通讯屏蔽。因此相比Corba,DCOM,SOAP,J2EE等的中间件技术,自然是集众多优点于一身,而且他简单易学。Ice是一个自由软件,所有代码都可用,是在GNUGeneral Public License (GPL)下发布的。
这里.服务端和客户端都使用VS.NET 2005开发,语言采用C#,
1,安装ice,这里安装在D:\Lib\Ice-3.3.0
2,编写DemoIce.ice文件,
// **********************************************************************
// Copyright (c) 2003-2008 ZhangEF, Inc. All rights reserved.
// **********************************************************************
#ifndef DEMO_ICE
#define DEMO_ICE
module Demo
{
enum DemoEnum
{
G722,
G726,
};
struct DemoStruct
{
int nValue;
string strValue;
DemoEnum eValue;
};
interface DemoIce
{
idempotent void SetEx(int nId, DemoStruct param);
["cpp:const"] idempotent void GetEx(int nId, out DemoStruct param);
};
}; //end module
#endif
3,编译成DemoIce.cs文件
path D:\Lib\Ice-3.3.0\bin
slice2cs.exe IceDemo.ice
4,创建.net2005 控制台项目添加现有项目 DemoIce.cs文件,添加引用 [ICE]\bin\Ice.dll
5,在服务断代码里实现抽象类的所有接口,抽象类在DemoIce.cs文件中,以Disp_结尾.
6,服务器端代码:
using System;
using System.Collections.Generic;
using System.Text;
using Demo;
using System.Reflection;
namespace IceServerCon
{
public class DemoIceI : DemoIceDisp_
{
DemoStruct m_data = new DemoStruct();
public override void GetEx(int nId, out DemoStruct param, Ice.Current current__)
{
param = m_data;
Console.WriteLine("GetEx() called");
}
public override void SetEx(int nId, DemoStruct param, Ice.Current current__)
{
m_data = param;
Console.WriteLine("SetEx() called");
}
}
class Program
{
static void Main(string[] args)
{
try
{
int status = 0;
Ice.Communicator ic = null;
try
{
ic = Ice.Util.initialize(ref args);
Ice.ObjectAdapter adapter = ic.createObjectAdapterWithEndpoints("DemoIce", "default -p 10000");
Ice.Object obj = new DemoIceI();
adapter.add(obj, ic.stringToIdentity("DemoIce"));
adapter.activate();
//ic.waitForShutdown();
}
catch (Exception e)
{
Console.Error.WriteLine(e);
status = 1;
}
Console.WriteLine("Server Start [OK]");
Console.ReadLine();
if (ic != null)
{
try
{
ic.destroy();
}
catch (Exception e)
{
Console.Error.WriteLine(e);
status = 1;
}
}
if (status != 0)
{
System.Environment.Exit(status);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
7,客户端代码
using System;
using System.Collections.Generic;
using System.Text;
using Demo;
namespace IceClientCon
{
class Program
{
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("DemoIce:tcp -h127.0.0.1 -p 10000").ice_twoway().ice_timeout(200).ice_secure(false);
DemoIcePrx demoIce = DemoIcePrxHelper.checkedCast(obj);
if (demoIce == null)
throw new ApplicationException("Invalid proxy");
DemoStruct data1 = new DemoStruct();
DemoStruct data2 ;
data1.strValue = "Hellow Server";
demoIce.SetEx(1, data1);
demoIce.GetEx(1, out data2);
Console.WriteLine("data2.strValue = {0}", data2.strValue);
}
catch (Exception e)
{
Console.Error.WriteLine(e);
status = 1;
}
Console.ReadLine();
if (ic != null)
{
try
{
ic.destroy();
}
catch (Exception e)
{
Console.Error.WriteLine(e);
status = 1;
}
}
if (status != 0)
{
System.Environment.Exit(status);
}
}
}
}
使用C#编写Zeroc?ICE应用程序的例子
ICE专题:使用C#编写ICE分布式应用程序
编写多线程的 Java 应用程序
使用C#编写扩展存储过程-C#技术文档 - Firnow
C#数组定义例子
面向 Java 开发人员的 Ajax: 使用 Jetty 和 Direct Web Remoting 编写可扩展的 Comet 应用程序
Keil C51编写的192x64液晶片驱动程序例子
浅析编写C#多线程
导学案的编写和使用
导学案的编写和使用
C# SerialPort控件的使用【转载】
学习ice的架构
获取和设置c# 应用程序目录
修改错误 一个MSFlexGrid控件的使用的例子
导学案的编写和使用1
导学案的编写和使用2
导学案的编写和使用(转)
C# 编写SQL SERVER 2005 的存储过程 - 9who - 博客园
移动用户更爱使用免费的新闻应用程序
使用异步 I/O 大大提高应用程序的性能
同花顺公式编写第六课:选次新股的公式源码编写和使用
对“导学案”的编写与使用的思考
使用Axis开发Webservice应用程序
使用C#开发ActiveX控件