基于C#的多线程P2P即时通讯系统

2021-03-07 12:36:37吴晓华梁哲刘同来
电脑知识与技术 2021年36期

吴晓华 梁哲 刘同来

摘要:为实现局域网内多个终端间信息、文件互通,同时满足用户对数据传输的即时性需求,结合P2P、Socket等通信技术,设计了一个多线程即时通讯系统。系统实现了局域网络中用户登录、在线用户列表实时更新、即时性信息传输以及文件传输等功能。系统摒弃第三方集中服务器,有效提升了数据传输的安全性;同时,数据传输不需第三方中转,其传输速率可得到大幅提升。此外,系统采用多线程通信技术,进一步加速了大文件的传输速率。

关键词:C#;P2P;局域网;多线程;Socket

中图分类号:TP311.52      文献标识码:A

文章编号:1009-3044(2021)36-0075-04

开放科学(资源服务)标识码(OSID):

A C#-based Multi-Thread P2P Communicating System

WU Xiao-hua1, LIANG Zhe2, LIU Tong-lai3

(1.Network and Information Technology Center, Guilin University of Electronic Technology, Guilin 541004, China; 2. China Mobile Guangxi Company, Nanning 530000, China; 3. College of Information Science and Technology, Zhongkai University of Agriculture and Engineering, Guangzhou 510225, China)

Abstract: To achieve the message and file interchange among multiple clients, as well as the immediacy demand of data transmission of the clients in a local area network, a multi-thread real-time communicating system is designed using technologies such as peer-to-peer, socket and so on. The system realized the functions of user login, real-time updates of online user list, real-time message and file transmission, etc. The system eliminates the third-party centralized server, which effectively improves the security of data transmission; In the meanwhile, since there is no need for a third party to transfer data, the data transmission rate can be greatly increased. In addition, the system uses multi-thread technology, which further accelerates the transmission rate of large files.

Key words: C#; P2P; LAN; multi-thread; Socket

1 背景

作为效率低、费用高的信件、电报、电话等老式通信技术的替代品,即时通讯系统因其快速、便捷等特点,被人们广泛应用于教育、商业以及社交活动中。同时,随着互联网技术的迅速发展,即时通讯系统被赋予越来越多先进的功能,如文件传输、远程视频等,其实时性也得到不断提高,给人们带来诸多便利。

现有的即时通讯系统,大多采用集中式服务器-客户端架构(即C/S架构)实现用户注册、登录以及好友列表等功能。在此网络架构下,用户凭据、聊天内容等重要信息存储在服务器端的数据库中,任何能够访问服务器和数据库的人都可以轻松访问用户信息,存在较大的安全隐患。同时,其资源损耗总是集中在服务器端,运营成本较大。此外,一旦服务器发生故障,数据损失将不可挽回。

作为另一通信方案,点对点架构(Peer to Peer,P2P),因其去中心化、健壮性、可扩展性等优势,广泛应用在即时通讯领域[1-2]。……

登录APP查看全文