• 大小: 0.07M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2024-05-03
  • 语言: C#
  • 标签: p2p  

资源简介

P2P通信

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;
using System.Threading;
using System.IO;

namespace P2P
{
    public partial class Form1 : Form
    {

        string UserName;
        string UserIP;
        string UserPort;
        

        private p2pdll p2pdlib = new p2pdll();

        public p2pdll.ClassMsg mySendmsg = new p2pdll.ClassMsg();

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender EventArgs e)
        {

            mySendmsg.type = p2pdll.msgType.SendText;
            mySendmsg.sendIP =UserIP;
            mySendmsg.sendName = UserName;
            mySendmsg.sendProt = UserPort;
            mySendmsg.Data = Encoding.Default.GetBytes(this.rtb_msg.Text);
            mySendmsg.recIP = this.txt_IP.Text;
            mySendmsg.recProt = UpD_ToPort.Text;
            p2pdlib.Send(mySendmsg);
            //p2pdlib.Send(this.rtb_msg.Text this.txt_IP.Text Convert.ToInt32(this.UpD_ToPort.Text));
            this.rtb_AllMsg.AppendText(“给[“ + mySendmsg.recIP + “] 发送:“ +this.rtb_msg.Text + “ \r\n“);
        }


        //void P2P_ReceivMsg(string msgstr)
        //{

        //    if (this.InvokeRequired)
        //    {
        //        p2pdll.ShowMessage update = new p2pdll.ShowMessage(this.P2P_ReceivMsg);
        //        this.Invoke(update new object[] { msgstr });
        //    }
        //    else
        //    {
        //        this.rtb_AllMsg.AppendText(msgstr + “ \r\n“);
        //    }
        //}

        void P2P_ReceivMsg(p2pdll.ClassMsg msgstr)
        {

            if (this.InvokeRequired)
            {
                p2pdll.ShowMessage update = new p2pdll.ShowMessage(this.P2P_ReceivMsg);
                this.Invoke(update new object[] { msgstr });
            }
            else
            {
   
                 if (msgstr.type == p2pdll.msgType.SendText)
                {
                    string msg = “接收到 [“ + msgstr.sendName + “(“ + msgstr.sendIP + “)“ + “]的消息:“ + System.Text.Encoding.UTF8.GetString(msgstr.Data);
                    this.rtb_AllMsg.AppendText(msg + “ \r\n“);
                }
                else if (msgstr.type == p2pdll.msgType.SendFile)
                {
                    string path;
                    string msg = “接收到 [“ + msgstr.sendName + “(“ + msgstr.sendIP + “)“ + “] 发过来的文件:“ + msgstr.Filename;
                    if (MessageBox.Show(msg“确认“MessageBoxButtons.YesNo) == DialogResult.No)
                    {
                        return;
                    }
                    path = Application.StartupPath + “\\“ + msgstr.Filename;
                    AuthToFile(pathmsgstr.Data);
                    this.rtb_

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2021-01-26 19:02  P2P\
     文件         189  2018-07-25 11:59  P2P\App.config
     文件       13981  2018-07-27 08:19  P2P\Form1.Designer.cs
     文件        9043  2018-07-27 09:14  P2P\Form1.cs
     文件        5817  2018-07-27 08:19  P2P\Form1.resx
     文件        4145  2018-07-26 08:41  P2P\P2P.csproj
     文件         228  2018-07-26 08:41  P2P\P2P.csproj.user
     文件       17672  2019-02-18 17:08  P2P\P2Pold.zip
     文件         526  2018-07-25 11:59  P2P\Program.cs
     目录           0  2018-07-25 11:59  P2P\Properties\
     文件        1418  2018-07-25 11:59  P2P\Properties\AssemblyInfo.cs
     文件        2836  2018-07-25 11:59  P2P\Properties\Resources.Designer.cs
     文件        5612  2018-07-25 11:59  P2P\Properties\Resources.resx
     文件        1090  2018-07-25 11:59  P2P\Properties\Settings.Designer.cs
     文件         249  2018-07-25 11:59  P2P\Properties\Settings.settings
     文件        2355  2018-07-25 13:45  P2P\SocketLib.cs
     目录           0  2021-01-26 18:51  P2P\bin\
     目录           0  2021-01-26 18:55  P2P\bin\Debug\
     文件       19968  2021-01-26 18:55  P2P\bin\Debug\P2P.exe
     文件         189  2018-07-25 11:59  P2P\bin\Debug\P2P.exe.config
     文件       38400  2021-01-26 18:55  P2P\bin\Debug\P2P.pdb
     目录           0  2021-01-26 18:51  P2P\obj\
     目录           0  2021-01-26 18:55  P2P\obj\Debug\
     文件         214  2021-01-26 18:51  P2P\obj\Debug\.NETframeworkVersion=v4.5.2.AssemblyAttributes.cs
     文件         669  2021-01-26 18:55  P2P\obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        7272  2021-01-26 18:55  P2P\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件         180  2021-01-26 18:55  P2P\obj\Debug\P2P.Form1.resources
     文件         180  2021-01-26 18:55  P2P\obj\Debug\P2P.Properties.Resources.resources
     文件          42  2021-01-26 18:55  P2P\obj\Debug\P2P.csproj.CoreCompileInputs.cache
     文件         735  2021-01-26 18:55  P2P\obj\Debug\P2P.csproj.FileListAbsolute.txt
     文件        1012  2021-01-26 18:55  P2P\obj\Debug\P2P.csproj.GenerateResource.cache
............此处省略7个文件信息

评论

共有 条评论