.Net Remoting 事件回調 Client 函數方法完整執行個體: C# 實現控制台網路聊天室 (Console Remoting ChatRoom)

來源:互聯網
上載者:User

.Net Remoting 事件回調 Client 函數方法完整執行個體: C# 實現控制台網路聊天室 (Console Remoting ChatRoom)
http://chs.gotdotnet.com/quickstart/howto/doc/Remoting/quickstart.aspx
編譯時間解析對遠程對象的用戶端引用的三種不同的方法為:
1.
編譯用戶端時,編譯伺服器對象並將 EXE 或 DLL 指定為對編譯器的引用。如果用戶端和伺服器組件都是在同一地點開發的,這種方法會非常有用。
2.
從介面類派生伺服器對象並使用介面編譯用戶端。如果用戶端和伺服器組件不是在同一地點開發時,這種方法會非常有用。可根據需要將介面編譯為 DLL 並發送到用戶端地點。應避免對發行的介面變更。有關更多資訊,請參考 COM 指南。
3.
使用 SOAPSUDS 工具從啟動並執行伺服器對象提取所需的中繼資料。如果用戶端和伺服器組件在不同的地點開發而且沒有可用的介面類,這會非常有用。將 SOAPSUDS 工具指向遠程 URI 並將所需中繼資料產生為源或 DLL。請注意,SOAPSUDS 工具僅提取中繼資料,不產生遠程對象的源。

本例採用方法 2
.Net Remoting 實現簡易的控制台聊天室

本套程式分別由 伺服器端和用戶端程式組成:
Server Side:
1.\RemotingChatRoom\Server\Share.cs
   csc.exe /t:library c:\RemotingChatRoom\Server\ChatRoom.cs
   產生的 Share.dll 部署在伺服器端,提供給 Client 的 Remoting 服務的類
2.\RemotingChatRoom\Server\Receiver.cs
   csc.exe /t:library c:\RemotingChatRoom\Server\Receiver.cs
   產生的 Receiver.dll 部署在伺服器端,此時該 server 與 Client 位置互換角色:
   Client 的 Receiver 對象,也要為 server 提供遠程服務,代理類即可。
3.\RemotingChatRoom\Server\Server.cs
   csc.exe c:\RemotingChatRoom\Server\Server.cs
   產生的 Server.exe 就是 Remoting Server 的主程式
4.\RemotingChatRoom\Server\s.config
   Server 端的 Remoting 設定檔

Client Side:
1.\RemotingChatRoom\Client\Share.cs
   csc.exe /t:library c:\RemotingChatRoom\Client\ChatRoom.cs
   產生的 Share.dll 部署在用戶端,
   該程式集的 ChatRoom 類的只是遠端伺服器端的相應程式集的 ChatRoom 類的代理類:
   命名空間 類 方法 等僅需簽名要與伺服器端一致即可。
   當然也可將伺服器端完整的遠程對象類的程式集直接部署在用戶端。
2.\RemotingChatRoom\Client\Sender.cs
   csc.exe /r:Share.dll c:\RemotingChatRoom\Client\Sender.cs
   產生的 Sender.exe 是用於 發言 的 Remoting 用戶端。
3.\RemotingChatRoom\Client\Receiver.cs
   csc.exe /r:ChatRoom.dll c:\RemotingChatRoom\Client\Receiver.cs
   產生的 Receiver.exe 是用於 接收所有發言 的 Remoting 用戶端。

請注意程式的注釋

完整執行個體下載:
http://files.cnblogs.com/Microshaoft/RemotingChatRoom.rar

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.