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

资源简介

TCP和UDP通信的小工具,有服务器端监听功能和客户端的连接功能,带有源码,适合初学者学习

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TCP_UDP
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private TcpListenerClass tcpListen = new TcpListenerClass();
        private TcpClientClass tcpClient = new TcpClientClass();

        private UdpServerClass udpServer = new UdpServerClass();
        private UdpServerClass udpClient = new UdpServerClass();

        private Netbase netListen = null;
        private Clientbase client = null;

        protected override void OnClosing(CancelEventArgs e)
        {
            if (!this.btnListen.Enabled)
            {
                netListen.StopListener();
            }
        }

        private void MainForm_Load(object sender EventArgs e)
        {
            tcpListen.sendListenData += new SendData(tcplisten_sendListenData);
            tcpListen.addIP += new SendIP(tcpListen_addIP);
            tcpListen.deleteIP += new SendIP(tcpListen_deleteIP);
            //
            tcpClient.sendClientData += new SendData(tcpClient_sendClientData);
            tcpClient.notifyDisConnect += new Notify(tcpClient_notifyDisConnect);
            //
            udpServer.SendListenData += new SendData(tcplisten_sendListenData);
            udpServer.sendIP += new SendIP(tcpListen_addIP);
            //
            udpClient.SendListenData += new SendData(tcpClient_sendClientData);
            //
            string[] ipstr = Netbase.GetLocalAddress();
            for (int i = 0; i < ipstr.Length; i++)
            {
                this.cmbIP.Items.Add(ipstr[i]);
            }
            if (this.cmbIP.Items.Count > 0)
                this.cmbIP.SelectedIndex = 0;
            // 选择通信协议
            SelectProtocol();
            SelectClientProtocol();
        }

        #region 服务器
        private void tcplisten_sendListenData(string ip byte[] data int length)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new SendData(tcplisten_sendListenData) new object[] { ip data length });
            }
            else
            {
                //if (this.lbDisplay.Items.Count >= 50)
                //    this.lbDisplay.Items.Clear();
                string str = ““;
                if (this.cbHexDis.Checked)
                {
                    for (int i = 0; i < length; i++)
                    {
                        str += Convert.ToString(data[i] 16).ToUpper().PadLeft(2 ‘0‘) + “ “;
                    }
                }
                else
                {
                    str = System.Text.ASCIIEncoding.Default.GetString(data);
                }
                this.lbDisplay.Items.Insert(0 ip + “ “ + str);
                this.l

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

     文件        911  2013-06-09 08:49  Socket\TCP_UDP.sln

    ..A..H.     50688  2014-03-19 16:14  Socket\TCP_UDP.suo

     文件      16190  2014-02-25 13:09  Socket\TCP_UDP\MainForm.cs

     文件      35161  2014-02-25 11:48  Socket\TCP_UDP\MainForm.Designer.cs

     文件       6221  2014-02-25 11:48  Socket\TCP_UDP\MainForm.resx

     文件        491  2013-06-09 08:38  Socket\TCP_UDP\Program.cs

     文件       4132  2013-06-09 08:38  Socket\TCP_UDP\TCP_UDP.csproj

     文件       1370  2013-06-09 08:38  Socket\TCP_UDP\Properties\AssemblyInfo.cs

     文件       2838  2013-06-09 08:38  Socket\TCP_UDP\Properties\Resources.Designer.cs

     文件       5612  2012-09-04 13:37  Socket\TCP_UDP\Properties\Resources.resx

     文件       1105  2013-06-09 08:38  Socket\TCP_UDP\Properties\Settings.Designer.cs

     文件        249  2012-09-04 13:37  Socket\TCP_UDP\Properties\Settings.settings

     文件       1501  2014-03-19 16:13  Socket\TCP_UDP\obj\Debug\TCP_UDP.csproj.FileListAbsolute.txt

     文件        850  2014-02-25 11:51  Socket\TCP_UDP\obj\Debug\TCP_UDP.csproj.GenerateResource.Cache

     文件      32256  2014-02-25 13:17  Socket\TCP_UDP\obj\Debug\TCP_UDP.exe

     文件        180  2014-02-25 11:51  Socket\TCP_UDP\obj\Debug\TCP_UDP.MainForm.resources

     文件      69120  2014-02-25 13:17  Socket\TCP_UDP\obj\Debug\TCP_UDP.pdb

     文件        180  2014-02-25 10:16  Socket\TCP_UDP\obj\Debug\TCP_UDP.Properties.Resources.resources

     文件       4608  2013-12-04 09:47  Socket\TCP_UDP\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll

     文件        286  2013-06-09 08:38  Socket\TCP_UDP\Library\Clientbase.cs

     文件        283  2013-06-09 08:38  Socket\TCP_UDP\Library\DelegateClass.cs

     文件       2236  2013-06-09 08:38  Socket\TCP_UDP\Library\IniClass.cs

     文件       1951  2013-06-09 08:39  Socket\TCP_UDP\Library\Netbase.cs

     文件       2865  2013-06-09 08:38  Socket\TCP_UDP\Library\TcpClientClass.cs

     文件       6856  2014-02-25 13:17  Socket\TCP_UDP\Library\TcpListenerClass.cs

     文件       3522  2013-12-31 16:01  Socket\TCP_UDP\Library\UdpServerClass.cs

     文件      32256  2014-02-25 13:17  Socket\TCP_UDP\bin\Debug\TCP_UDP.exe

     文件      69120  2014-02-25 13:17  Socket\TCP_UDP\bin\Debug\TCP_UDP.pdb

     文件      14328  2014-03-19 16:13  Socket\TCP_UDP\bin\Debug\TCP_UDP.vshost.exe

     文件        490  2007-07-21 01:33  Socket\TCP_UDP\bin\Debug\TCP_UDP.vshost.exe.manifest

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

评论

共有 条评论