• 大小: 358KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-07
  • 语言: C#
  • 标签: P2P  聊天  c#  源码  程序  

资源简介

用c#语言编写的P2P聊天程序源代码 很经典的例子,

资源截图

代码片段和文件信息

//  Copyright (c) Microsoft Corporation.  All Rights Reserved.

using System;

using System.ServiceModel.Channels;
using System.Collections.Generic;
using System.Collections.objectModel;
using System.Configuration;
using System.Net;
using System.Net.Sockets;
using System.ServiceModel;
using System.ServiceModel.Configuration;
using System.ServiceModel.PeerResolvers;


// Custom peer resolver client-side implementation. Derives from PeerResolver and delegates the actual
// registration unregistration and resolution to the resolver service (which is a separate application).

// If you are unfamiliar with new concepts used in this sample refer to the WCF Basic\GettingStarted sample.

namespace ChatClientComponent
{
    // CustomPeerResolver Service contract. It is manually generated since svcutil currently does not
    // support WSDL generation when EndpointAddress[] is used in the service contract.
    [ServiceContract(Namespace = “http://P2PChat“)]
    public interface ICustomPeerResolver
    {
        [OperationContract]
        int Register(string meshId PeerNodeAddress nodeAddresses);
        [OperationContract]
        void Unregister(int registrationId);
        [OperationContract]
        void Update(int registrationId PeerNodeAddress updatedNodeAddress);
        [OperationContract]
        PeerNodeAddress[] Resolve(string meshId int maxAddresses);
        [OperationContract]
        List GetExistingMeshes();
    }

    public interface ICustomPeerResolverChannel : ICustomPeerResolver IClientChannel
    {
    }

    public class CustomPeerResolver : PeerResolver
    {
        const string config = “CustomPeerResolverEndpoint“;

        // Allow the clients to share referals
        public override bool CanShareReferrals
        {
            get { return true; }
        }

        // Register address for a node participating in a mesh identified by meshId with the resolver service
        public override object Register(string meshId PeerNodeAddress nodeAddress TimeSpan timeout)
        {
            ChannelFactory factory = new ChannelFactory(config);

            ICustomPeerResolverChannel client = factory.CreateChannel();

            MaskScopeId(nodeAddress.IPAddresses);
            int registrationId = client.Register(meshId nodeAddress);

            client.Close();

            factory.Close();

            return registrationId;
        }

        // Unregister address for a node from the resolver service
        public override void Unregister(object registrationId TimeSpan timeout)
        {
            ChannelFactory factory = new ChannelFactory(config);

            ICustomPeerResolverChannel client = factory.CreateChannel();
            client.Unregister((int)registrationId);
            client.Close();

            factor

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       2899  2006-09-18 10:19  P2Pliaotian\ChatClientComponent\ChatClientComponent.csproj

     文件       7416  2006-09-18 10:25  P2Pliaotian\ChatClientComponent\CustomPeerResolver.cs

     文件        356  2006-09-20 11:00  P2Pliaotian\ChatClientComponent\obj\ChatClientComponent.csproj.FileList.txt

     文件      24576  2006-09-20 09:51  P2Pliaotian\ChatClientComponent\obj\Debug\ChatClientComponent.dll

     文件      34304  2006-09-20 09:51  P2Pliaotian\ChatClientComponent\obj\Debug\ChatClientComponent.pdb

     文件      87452  2006-09-19 17:24  P2Pliaotian\ChatClientComponent\obj\Debug\ResolveAssemblyReference.cache

     文件       5825  2006-09-20 09:51  P2Pliaotian\ChatClientComponent\PeerManager.cs

     文件       3660  2006-09-19 10:53  P2Pliaotian\ChatClientComponent\PeerService.cs

     文件       1413  2006-09-18 09:15  P2Pliaotian\ChatClientComponent\Properties\AssemblyInfo.cs

     文件       2382  2006-09-18 09:56  P2Pliaotian\ChatPeer\ChatPeer.csproj

     文件        955  2006-09-18 09:55  P2Pliaotian\ChatPeer\DnsHelper.cs

     文件       3668  2006-09-18 09:55  P2Pliaotian\ChatPeer\IPeer.cs

     文件        605  2006-09-18 09:55  P2Pliaotian\ChatPeer\IPeerService.cs

     文件       1391  2006-09-18 09:25  P2Pliaotian\ChatPeer\Properties\AssemblyInfo.cs

     文件        297  2006-09-20 10:11  P2Pliaotian\ChatServer\App.xaml

     文件        290  2006-09-20 10:11  P2Pliaotian\ChatServer\App.xaml.cs

     文件       1952  2006-09-20 10:47  P2Pliaotian\ChatServer\bin\Debug\App.config

     文件       4350  2006-09-20 11:06  P2Pliaotian\ChatServer\ChatServer.csproj

     文件        168  2006-09-20 10:42  P2Pliaotian\ChatServer\ChatServer.csproj.user

     文件       1925  2006-09-20 11:04  P2Pliaotian\ChatServer\obj\Debug\App.g.cs

     文件        254  2006-09-20 11:06  P2Pliaotian\ChatServer\obj\Debug\ChatServer_MarkupCompile.cache

     文件       1538  2006-09-20 11:04  P2Pliaotian\ChatServer\obj\Debug\Window1.baml

     文件       2663  2006-09-20 11:04  P2Pliaotian\ChatServer\obj\Debug\Window1.g.cs

     文件       2052  2006-09-20 10:11  P2Pliaotian\ChatServer\Properties\AssemblyInfo.cs

     文件       2401  2006-09-20 10:11  P2Pliaotian\ChatServer\Properties\Resources.cs

     文件       5618  2006-09-20 10:11  P2Pliaotian\ChatServer\Properties\Resources.resx

     文件       1371  2006-09-20 10:11  P2Pliaotian\ChatServer\Properties\Settings.cs

     文件        203  2006-09-20 10:11  P2Pliaotian\ChatServer\Properties\Settings.settings

     文件       1360  2006-09-20 10:33  P2Pliaotian\ChatServer\Window1.xaml

     文件       1844  2006-09-20 10:58  P2Pliaotian\ChatServer\Window1.xaml.cs

............此处省略95个文件信息

评论

共有 条评论