• 大小: 68KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-14
  • 语言: C#
  • 标签: C#UDP  

资源简介

一个很垃圾的程序,不过对于一些刚入门的人来说的确是一个很好的参考

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;
using System.Threading;
namespace netHomework
{
    public partial class Form1 : Form
    {
        private UdpClient receive;
        private UdpClient udpClient;
        private int remotPort = 1000;
        private int localPort =1001;
        private Thread t;


        public Form1()
        {
            InitializeComponent();
            receive = new UdpClient(localPort);
            udpClient = new UdpClient();
        }

        private void sendButton_Click(object sender EventArgs e)
        {
            if (this.remotIPTextBox.Text.Equals(““))
            {
                MessageBox.Show(“应用了默认的127.0.0.1“);
            }
            udpClient.Send(Encoding.Unicode.GetBytes(this.contendTextBox.Text) Encoding.Unicode.GetByteCount(this.contendTextBox.Text)this.remotIPTextBox.Textthis.remotPort);
            this.sendButton.Enabled = false;

        }

        private void Form1_Load(object sender EventArgs e)
        {
            t = new Thread(new ThreadStart(receiveMethod));
            t.Start();

        }
        public void receiveMethod()
        {
            while (true)
            {
                IPEndPoint receivePoint = new IPEndPoint(IPAddress.Parse(“127.0.0.1“) 1);
                byte[] contendByte = receive.Receive(ref receivePoint);
                string contendLine = Encoding.Unicode.GetString(contendByte);
                this.informationTextBox.Text = contendLine;
                if (contendLine.Equals(“ack“))
                {
                    this.sendButton.Enabled = true;
                }
                else if (contendLine.Equals(“nak“))
                {
                    MessageBox.Show(“对方要求重发!“);
                    udpClient.Send(Encoding.Unicode.GetBytes(this.contendTextBox.Text) Encoding.Unicode.GetByteCount(this.contendTextBox.Text) this.remotIPTextBox.Text remotPort);
                }
                else if (contendLine.Equals(“none“))
                {
                    MessageBox.Show(“丢包咯!“);
                    this.sendButton.Enabled = true;
                }
                else if (contendLine.Equals(“outTime“))
                {
                    MessageBox.Show(“超时了不好意识!“);
                    this.sendButton.Enabled = true;
                }
            }
        }
        private void resetButton_Click(object sender EventArgs e)
        {
            this.remotIPTextBox.Text = ““;
            this.contendTextBox.Text = ““;
        }

        private void contendTextBox_TextChanged(object sender EventArgs e)
        {

        }
    }
}

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

     文件      20480  2009-04-11 15:09  receive\receive\bin\Debug\receive.exe

     文件      32256  2009-04-11 15:09  receive\receive\bin\Debug\receive.pdb

     文件       5632  2005-12-08 14:51  receive\receive\bin\Debug\receive.vshost.exe

     文件       2403  2009-04-11 15:09  receive\receive\Form1.cs

     文件       5612  2009-04-11 15:09  receive\receive\Form1.Designer.cs

     文件       5814  2009-04-09 16:53  receive\receive\Form1.resx

     文件        842  2009-04-09 16:53  receive\receive\obj\Debug\receive.csproj.GenerateResource.Cache

     文件      20480  2009-04-11 15:09  receive\receive\obj\Debug\receive.exe

     文件        180  2009-04-09 16:53  receive\receive\obj\Debug\receive.Form1.resources

     文件      32256  2009-04-11 15:09  receive\receive\obj\Debug\receive.pdb

     文件        180  2009-04-09 16:12  receive\receive\obj\Debug\receive.Properties.Resources.resources

     文件        268  2009-04-09 17:46  receive\receive\obj\receive.csproj.FileList.txt

     文件        636  2009-04-11 15:13  receive\receive\obj\receive.csproj.FileListAbsolute.txt

     文件        466  2009-04-09 15:59  receive\receive\Program.cs

     文件       1228  2009-04-09 15:59  receive\receive\Properties\AssemblyInfo.cs

     文件       2868  2009-04-09 15:59  receive\receive\Properties\Resources.Designer.cs

     文件       5612  2009-04-09 15:59  receive\receive\Properties\Resources.resx

     文件       1090  2009-04-09 15:59  receive\receive\Properties\Settings.Designer.cs

     文件        249  2009-04-09 15:59  receive\receive\Properties\Settings.settings

     文件       3221  2009-04-09 17:02  receive\receive\receive.csproj

     文件        910  2009-04-09 15:59  receive\receive.sln

    ..A..H.     15872  2009-04-11 15:15  receive\receive.suo

     文件      20480  2009-04-11 15:14  netHomework\netHomework\bin\Debug\netHomework.exe

     文件      26112  2009-04-11 15:14  netHomework\netHomework\bin\Debug\netHomework.pdb

     文件       5632  2005-12-08 14:51  netHomework\netHomework\bin\Debug\netHomework.vshost.exe

     文件       2911  2009-04-11 15:14  netHomework\netHomework\Form1.cs

     文件       5340  2009-04-11 15:14  netHomework\netHomework\Form1.Designer.cs

     文件       5814  2009-04-09 16:39  netHomework\netHomework\Form1.resx

     文件       3229  2009-04-09 16:10  netHomework\netHomework\netHomework.csproj

     文件        842  2009-04-09 16:41  netHomework\netHomework\obj\Debug\netHomework.csproj.GenerateResource.Cache

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

评论

共有 条评论