当前注册人数423093人 邮箱: 密码: 注册新用户 忘记密码
首页 C/C++/MFC C# ASP.NET VB.NET MATLAB Android   站内搜索 下载代码说明/积分规则
为什么要注册?

1. 可以直接免费从本站下载代码,防止邮件发送不到您的邮箱,或登录不了国外网站

2. 可以设定关键字,当有您关心的代码收录时,邮件通知您

3. 对这里的代码进行评分和评论

4. 可以和大家一起分享你的源代码,得到更多的建议

Using Asynchronous Sockets for Peer-to-Peer - CollaborativeNotes

C#中使用异步Socket实现点对点通信

2007年12月22日
C# (C# 2.0), C#, Windows, .NET (.NET 2.0), .NET, Dev
本代码通过异步套接字实现点对点通信,基本想法是用于多个客户端直接相互通信而不经过服务器。
相关知识

代码片段

public InitState Initialize()
{
    ...
    IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName());
    ...
    IPAddress localAddress = null;
    for (int i = 0; i < hostEntry.AddressList.Length; ++i)
    {
        //IPv4 address
        if (hostEntry.AddressList[i].AddressFamily==AddressFamily.InterNetwork) 
        
            localAddress = hostEntry.AddressList[i];
    }
    ...
    try
    {
        if(mListenerSocket==null)
            mListenerSocket=new Socket(AddressFamily.InterNetwork, 
                SocketType.Stream, ProtocolType.Tcp);
        IPEndPoint localIP = new IPEndPoint(localAddress, mListenPort);
        mListenerSocket.Bind(localIP);
        //the best value to use here depends on each person alone
        mListenerSocket.Listen(50); 
        mListenerSocket.BeginAccept(new AsyncCallback(OnHandleClientConnection), null);
    }
    catch ...
    ...
}
源代码原文下载:
Using Asynchronous Sockets for Peer-to-Peer - CollaborativeNotes This article presents a peer-to-peer application sample with asynchronous sockets. This project was born from the desire to have some way that would allow for multiple client applications to communicate between each other. These clients would be in a network environment without having a relay server as in IRC. The goal was to achieve an environment of a collaborating workgroup by sharing a white board where all the elements could write/place their notes and contributions. As a result, there’s only a server which acts as a peer repository, so that new peers can join a given workgroup and be aware of who is online already, and then all the data is communicated directly from client to client.

源码图片

点击链接查看大图
从本站下载附件及源代码(1个附件,已经成功下载2395次)

最值得关注的外文源代码

WCF / WPF Chat Application
p2p voip system supporting h.323 and sip
WCF / WPF Chat Application
DVB Open Transmission Core
评论(评论是增加积分的一个有效途径)
字数在300字内
请如实评论
本源代码共评论315次,此处显示最近20次评论! 查看所有评论

云雀  2023年07月24日
积分,先收藏了
木刀  2018年01月11日
赚个积分吧先
你好外星人  2017年12月18日
積分不夠@@
livingandlearning  2017年08月31日
很好的资源,谢谢分享
livingandlearning  2017年08月31日
刚好学习这部分知识,很实用
goodliness  2017年04月07日
学习一下,谢谢楼主分享!
lf8013  2017年02月04日
初学的,下来看看学习一下
lf8013  2017年02月03日
初学的,下来看看学习一下
Anyou2010  2015年07月30日
看看,学习一下。。。
iiop  2015年01月07日
积分不够了
聆听雨点丶Kb  2014年07月25日
我要
bryan  2014年07月18日
積分不夠@@
wanju  2014年04月14日
值得学习
Zeal0t  2014年01月08日
谢谢 好用
Zeal0t  2014年01月07日
不错,值得研究学习一下,谢谢分享!
suysulin  2014年01月06日
学习一下,谢谢楼主!
ord2011  2013年07月26日
不错,值得研究学习一下,谢谢分享!
飞扬的枫  2013年07月24日
值得研究的实例
osric  2013年07月22日
不错
scsc4212  2013年05月08日
谢谢分享
字数在300字内
请如实评论
200万国内源码搜索
CopyRight (C) codesoso.com 2007-2009 All Rights Reserved zhihuishi   免责声明