• 大小: 57KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-13
  • 语言: C#
  • 标签: C#  TCP  C/S  多线程  

资源简介

该程序实现一个界面管理,通过通讯设置自主选择服务器和客户端,实现多线程通信,代码简单易懂,适合初学者。

资源截图

代码片段和文件信息

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;
using System.Net;//
using System.Net.Sockets;//
using System.Threading;

namespace Comunication_v1._0
{
    public partial class Form1 : Form
    {
        private int _protocal;//定义这三个变量,留着从协议设置里取数据
        private IPAddress _ipAddr;
        private int _port;
        private bool flag;//这个量用来判断按钮按下时是什么状态
        mySocket con;
        Thread thread1;
        Thread thread2;
        
        public Form1()
        {
            InitializeComponent();
            flag = true;
            con = new mySocket();
        }

        /// 
        /// 让mySocket类中的函数可以调用Form1类中的控件
        /// 

        /// 
        /// 
        private void Form1_Shown(object sender EventArgs e)
        {
            CheckForIllegalCrossThreadCalls = false;
            con.tb3 = textBox3;
            con.tb4 = textBox4;
            con.lb5 = label5;
            con.cb2 = comboBox2;
        }

        /// 
        /// 检查通讯设置有没有问题
        /// 

        /// 
        private bool ValidateInput()
        {
            _protocal = comboBox1.SelectedIndex;
            if (_protocal == -1)
            { 
                MessageBox.Show(“请在通讯设置里选择协议类型““提示“MessageBoxButtons.OKMessageBoxIcon.Information);
                return false;
            }

            if (!IPAddress.TryParse(textBox1.Text out _ipAddr))
            {
                MessageBox.Show(“无效IP地址“ “提示“ MessageBoxButtons.OK MessageBoxIcon.Information);
                return false;
            }

            if (!int.TryParse(textBox2.Text out _port))
            {
                MessageBox.Show(“无效端口号“ “提示“ MessageBoxButtons.OK MessageBoxIcon.Information);
                return false;
            }
            else if (_port < 1024 || _port > 65535)
            {
                MessageBox.Show(“无效端口号“ “提示“ MessageBoxButtons.OK MessageBoxIcon.Information);
                return false;
            }

            return true;
        }

        /// 
        /// 这里根据通讯协议调整一下窗口上的输入提示
        /// 

        /// 
        /// 
        private void comboBox1_SelectedIndexChanged(object sender EventArgs e)
        {
            _protocal = comboBox1.SelectedIndex;
            if (_protocal == 0) 
            {
                label2.Text = “本机IP地址“;
                label3.Text = “监听端口号“;
            }
            else
            {
                label2.Text = “目的IP地址“;
                label3.Text = “目的端口号“;
            }
        }
        
        /// 
        /// 启动
        /// 

        /// 
       

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

     文件      17408  2014-06-29 12:35  Comunication_v1.1\Comunication_v1.0\bin\Debug\Comunication_v1.0.exe

     文件      36352  2014-06-29 12:35  Comunication_v1.1\Comunication_v1.0\bin\Debug\Comunication_v1.0.pdb

     文件      11600  2014-06-29 12:36  Comunication_v1.1\Comunication_v1.0\bin\Debug\Comunication_v1.0.vshost.exe

     文件        490  2009-08-31 00:40  Comunication_v1.1\Comunication_v1.0\bin\Debug\Comunication_v1.0.vshost.exe.manifest

     文件       3733  2014-06-27 18:39  Comunication_v1.1\Comunication_v1.0\Comunication_v1.1.csproj

     文件       7512  2014-06-29 12:25  Comunication_v1.1\Comunication_v1.0\Form1.cs

     文件      12930  2014-06-28 09:58  Comunication_v1.1\Comunication_v1.0\Form1.Designer.cs

     文件       5817  2014-06-28 09:58  Comunication_v1.1\Comunication_v1.0\Form1.resx

     文件       6290  2014-06-29 12:38  Comunication_v1.1\Comunication_v1.0\mySocket.cs

     文件       1069  2014-06-29 10:27  Comunication_v1.1\Comunication_v1.0\obj\x86\Debug\Comunication_v1.0.csproj.FileListAbsolute.txt

     文件      17408  2014-06-29 12:35  Comunication_v1.1\Comunication_v1.0\obj\x86\Debug\Comunication_v1.0.exe

     文件      36352  2014-06-29 12:35  Comunication_v1.1\Comunication_v1.0\obj\x86\Debug\Comunication_v1.0.pdb

     文件        885  2014-06-29 12:36  Comunication_v1.1\Comunication_v1.0\obj\x86\Debug\Comunication_v1.1.csproj.FileListAbsolute.txt

     文件        180  2014-06-29 11:04  Comunication_v1.1\Comunication_v1.0\obj\x86\Debug\Comunication_v1._0.Form1.resources

     文件        180  2014-06-29 11:04  Comunication_v1.1\Comunication_v1.0\obj\x86\Debug\Comunication_v1._0.Properties.Resources.resources

     文件       4440  2014-06-27 08:01  Comunication_v1.1\Comunication_v1.0\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6262  2014-06-29 12:35  Comunication_v1.1\Comunication_v1.0\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        304  2014-06-29 11:04  Comunication_v1.1\Comunication_v1.0\obj\x86\Debug\GenerateResource.read.1.tlog

     文件        750  2014-06-29 11:04  Comunication_v1.1\Comunication_v1.0\obj\x86\Debug\GenerateResource.write.1.tlog

     文件        499  2014-06-26 17:28  Comunication_v1.1\Comunication_v1.0\Program.cs

     文件       1366  2014-06-26 17:28  Comunication_v1.1\Comunication_v1.0\Properties\AssemblyInfo.cs

     文件       2887  2014-06-26 17:28  Comunication_v1.1\Comunication_v1.0\Properties\Resources.Designer.cs

     文件       5612  2014-06-26 17:28  Comunication_v1.1\Comunication_v1.0\Properties\Resources.resx

     文件       1104  2014-06-26 17:28  Comunication_v1.1\Comunication_v1.0\Properties\Settings.Designer.cs

     文件        249  2014-06-26 17:28  Comunication_v1.1\Comunication_v1.0\Properties\Settings.settings

     文件        893  2014-06-29 10:33  Comunication_v1.1\Comunication_v1.1.sln

    ..A..H.     24576  2014-06-29 12:43  Comunication_v1.1\Comunication_v1.1.suo

     目录          0  2014-06-26 17:28  Comunication_v1.1\Comunication_v1.0\obj\x86\Debug\TempPE

     目录          0  2014-06-29 12:35  Comunication_v1.1\Comunication_v1.0\obj\x86\Debug

     目录          0  2014-06-29 11:04  Comunication_v1.1\Comunication_v1.0\bin\Debug

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

评论

共有 条评论