C++ rtmp livestream 流媒体

海阔天空 张翼飞翔

我的学习笔记。--我喜欢这里,因为这里安静,无广告骚扰。
随笔 - 82, 文章 - 2, 评论 - 126, 引用 - 0
数据加载中……

使用C#编写Zeroc ICE应用程序的例子

使用C#编写Zeroc ICE应用程序的例子 
    Internet Communications Engine (Ice) 是现代面向对象的中间件,它支持C++, C#, Java, Python, Ruby, PHP, 和 Visual Basic开发语言。Zeroc ICE中间件号称标准统一,开源,跨平台,跨语言,分布式,安全,服务透明,负载均衡,面向对象,性能优越,防火期穿透,通讯屏蔽。因此相比Corba,DCOM,SOAP,J2EE等的中间件技术,自然是集众多优点于一身,而且他简单易学。Ice是一个自由软件,所有代码都可用,是在GNU General 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 -h 127.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(
1out 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);
            }

        }

    }

}



posted on 2009-03-06 17:27 ZhangEF 阅读(2368) 评论(2)  编辑  收藏 所属分类: 配置部署

评论

# re: 使用C#编写Zeroc ICE应用程序的例子  回复  更多评论   

大哥是否有ice 3.3.1早期版本的源码
最近我下载的源码都是删减过的,有很多都是缺少文件,我记得去年(2009年8月)的时候下载的是可以完整编译的,最近下的却不行.
所以如果大哥有可以完整编译通过的代码的话,请发给我,感激涕零.
我的qq是284165841,email:ldr12@163.com

因为急用,如果大哥您方便的话,请给我一份,呵呵
小弟感激不尽,呵呵
2010-04-11 16:44 | 海浪

# re: 使用C#编写Zeroc ICE应用程序的例子  回复  更多评论   

补充:
我用C++编译的,呵呵
2010-04-11 16:45 | 海浪