65.9K
CodeProject 正在变化。 阅读更多。
Home

使用 .NET Remoting 的简单聊天应用程序

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.57/5 (41投票s)

2001 年 11 月 14 日

1分钟阅读

viewsIcon

315495

downloadIcon

5778

此应用程序演示局域网中的 .NET Remoting。

Sample Image - DotNETChatApplication.gif

引言

该应用程序是一个简单的聊天工具。任何连接到聊天服务器的人都会收到连接用户之间的所有聊天通信。该应用程序被故意保持简单,以阐明 .NET Remoting。此应用程序还演示了在应用程序中使用 .NET Remoting 时的事件和委托用法。

描述

你们中的大多数人可能已经注意到,Visual Studio .NET 中有向导来开发 ASP.NET Web 服务。但是,如果您想开发在局域网上传输运行的客户端/服务器应用程序,则没有可用的向导。此应用程序演示了如何在局域网中进行 .NET Remoting。此应用程序的作用类似于 DCOM 服务器和客户端应用程序。此 Visual Studio .NET 解决方案包含三个模块。

  1. ChatCoordinator:服务器实现。
  2. ChatClient:客户端实现。
  3. ChatServer:Chat Coordinator 的运行时宿主。

它使用 HTTP 协议模式,并通过 HTTP 通道发送消息。远程配置在 ChatClient.exe.config 文件和 ChatServer.exe.config 文件中指定。

如何构建应用程序

  • 步骤 1:解压缩文件 DotNETChatApplication_demo.zip
  • 步骤 2:在 Visual Studio .NET 中打开文件 ChatApplication.sln
  • 步骤 3:构建解决方案。

如何运行应用程序

  • 步骤 1:找到项目文件夹下的 Output 文件夹。
  • 步骤 2:运行服务器应用程序 ChatServer.exe
  • 步骤 3:运行聊天客户端 ChatClient.exe

此应用程序可以在单台计算机或通过网络运行。如果您想通过网络运行此应用程序,则必须将客户端配置中的“localhost”替换为远程计算机的名称。修改 Client.exe.config 中的以下行

<wellknown type="ChatCoordinator.ChatCenter, ChatCoordinator" 
    url="https://:100/ChatServer" />

...

<wellknown type="ChatCoordinator.ChatCenter, ChatCoordinator" 
    url="http://your machine name:100/ChatServer" />

另外,请确保在运行 ChatClient.exe 之前,ChatServer.exe 正在运行。

© . All rights reserved.