冰聊应用

发布于 2024-10-12 18:33:14 字数 1863 浏览 4 评论 0 原文

我是 ICE 初学者。在 http://zeroc.com 上有关于如何创建聊天的很好的教程。我决定使用教程作为基础。我尝试做的第一件事是用 C# 编写 ChatRoom 类,而不是给定的 C++ 实现。我尝试在我的 C# 代码中执行相同的操作。 C++ 中的 ChatRoom 实现:

// C++
class ChatRoomCallbackAdapter { /* ... */ };
typedef IceUtil::Handle<ChatRoomCallbackAdapter> ChatRoomCallbackAdapterPtr;
class ChatRoom : public IceUtil::Shared
{
public:
    ChatRoom(bool trace, const Ice::LoggerPtr& logger);
    void reserve(const std::string&);
    void unreserve(const std::string&);
    void join(const std::string&, const ChatRoomCallbackAdapterPtr&);
    void leave(const std::string&);
    Ice::Long send(const std::string&, const std::string&);
private:
    typedef std::map<std::string, ChatRoomCallbackAdapterPtr> ChatRoomCallbackMap;
    ChatRoomCallbackMap _members;
    std::set<std::string> _reserved;
    IceUtil::Mutex _mutex;
    const bool _trace;
    const Ice::LoggerPtr _logger;
};

一些类成员实现:

// ...
void ChatRoom::reserve(const string& name)
{
    IceUtil::Mutex::Lock sync(_mutex);
    if(_reserved.find(name) != _reserved.end() ||
       _members.find(name) != _members.end())
    {
        throw string("The name " + name + " is already in use.");
    }
    _reserved.insert(name);
}
// ...

我接下来写的是:

public class ChatRoom : IceUtil

当我遇到错误时。我发现分发包中的 IceUtil dll 不是 COM 可见的,因此我无法在我的 c# 项目中使用它。

我可以用什么来代替c++,

IceUtil::Handle<T>

据我所知, 它是一个智能指针。 如何实现像 C# 中给出的服务器那样的服务器?

与上面的 c++ 类相比,c# 中(谈论互斥体)是否相同:

public class ChatRoom
{
    // ...
    void Reserve(System.String Name)
    {
        lock(this)
        {
            // operations
        }
    }               
}


谢谢!

I'm ICE starter. At http://zeroc.com there is good tutorial on how to create chat. I decided to use the tutorial as base. And first thing I tried to do was writing ChatRoom class in c# instead of given c++ implementation. I tried to do the same in my c# code. ChatRoom implementation in c++:

// C++
class ChatRoomCallbackAdapter { /* ... */ };
typedef IceUtil::Handle<ChatRoomCallbackAdapter> ChatRoomCallbackAdapterPtr;
class ChatRoom : public IceUtil::Shared
{
public:
    ChatRoom(bool trace, const Ice::LoggerPtr& logger);
    void reserve(const std::string&);
    void unreserve(const std::string&);
    void join(const std::string&, const ChatRoomCallbackAdapterPtr&);
    void leave(const std::string&);
    Ice::Long send(const std::string&, const std::string&);
private:
    typedef std::map<std::string, ChatRoomCallbackAdapterPtr> ChatRoomCallbackMap;
    ChatRoomCallbackMap _members;
    std::set<std::string> _reserved;
    IceUtil::Mutex _mutex;
    const bool _trace;
    const Ice::LoggerPtr _logger;
};

Some piece of class-members implementation:

// ...
void ChatRoom::reserve(const string& name)
{
    IceUtil::Mutex::Lock sync(_mutex);
    if(_reserved.find(name) != _reserved.end() ||
       _members.find(name) != _members.end())
    {
        throw string("The name " + name + " is already in use.");
    }
    _reserved.insert(name);
}
// ...

I was writng next:

public class ChatRoom : IceUtil

when I encountered an error. I found that IceUtil dll in distribution package isn't COM-visible therefore I can't use it in my c# project.

What can I use instead of c++

IceUtil::Handle<T>

as far as I understand it is a smart pointer.
How can I implement server like the one's given in c#?

Would it be the same in c# (talking about mutexes) comparing to above c++ class:

public class ChatRoom
{
    // ...
    void Reserve(System.String Name)
    {
        lock(this)
        {
            // operations
        }
    }               
}

?
Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紫罗兰の梦幻 2024-10-19 18:33:14

我对 ICE 一无所知,但他们的网站列出了 .NET 实现 - 你为什么不呢如果您想使用 C#,请使用它而不是 COM?甚至还有文档部分,其中包含 C# 服务器示例< /a>.

I don't know anything about ICE, but their website lists a .NET implementation - why don't you use that instead of COM if you want to use C#? There's even a section of documentation with an example of a C# server.

以往的大感动 2024-10-19 18:33:14

C++ 不支持开箱即用的引用计数指针,这就是为什么 C++ API 具有 IceUtil::Handle 模板。 C#显然不需要它。我建议您开始使用 C# 示例而不是 C++ 来学习 Ice for C#。您可以在 演示包。当然,Ice 与 COM 技术完全无关,只是它是一种替代品。

C++ does not support reference counted pointers out of the box, that is why C++ API has IceUtil::Handle<> template. C# obviously does not need it. I'd recommend you start learning Ice for C# using C# examples rather than C++. You can find a lot of C# client/server examples in democs folder of demos packages. And, of course, Ice has absolutely nothing to do with COM technology, except that it is kind of a replacement.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文