• 大小: 0.30M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2024-04-27
  • 语言: C#
  • 标签: TCP/IP  tcp  通讯  IP  

资源简介

TCP/IP通讯 有客户端与服务端

资源截图

代码片段和文件信息

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.IO;
using System.Threading;

namespace client
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public TcpClient TcpClient;        
        StreamReader ClientReader;
        StreamWriter ClientWriter;
        NetworkStream Stream;
        Thread Thd;

        private void btn_Click(object sender EventArgs e)
        {
            try
            {
                    if(Stream.DataAvailable)
                    {
                        rtxChatInfo.AppendText( DateTime.Now.ToString());
                        rtxChatInfo.AppendText(“ 服务器说:\n“);
                        rtxChatInfo.AppendText(ClientReader.ReadLine()+“\n“ );
                        //下拉框
                        rtxChatInfo.Selectionstart = rtxChatInfo.Text.Length;
                        rtxChatInfo.Focus();
                        rtxSendMessage.Focus();
                    }
            }
            catch 
            {

                //MessageBox.Show(ex.ToString());
            }
        }

        private void timer1_Tick(object sender EventArgs e)
        {
            btn_Click(sender e);
        }

        private void Form1_FormClosing(object sender FormClosingEventArgs e)
        {
            DialogResult dr = MessageBox.Show(“这样会中断与服务器的连接你要关闭该窗体吗?“ “客户端信息“ MessageBoxButtons.YesNo MessageBoxIcon.Warning); ;
            if (DialogResult.Yes == dr)
            {
                e.Cancel = false;
                Thd.Abort();
               
            }
            else
            {
                e.Cancel = true;
            }
           
        }

        private void Form1_Load(object sender EventArgs e)
        {
          //  skinEngine1.SkinFile = “MP10.ssk“;
        }

        private void btnClose_Click(object sender EventArgs e)
        {
            if (MessageBox.Show(“你确定要关闭吗?“ “提示“ MessageBoxButtons.OKCancel MessageBoxIcon.Information) == DialogResult.OK)
            {
                this.Close();
            }
        }

        private void btnConnect_Click(object sender EventArgs e)
        {
            if (txtServerIp.Text.Trim() == ““)
            {
                MessageBox.Show(“请输入服务器IP“ “客户端信息“ MessageBoxButtons.OK MessageBoxIcon.Error);
                return;
            }
            else
            {
                Thd = new Thread(new ThreadStart(GetConn));
                Thd.Start();
            }
        }
        public void GetConn()
        {
            CheckForIllegalCrossThreadCalls = false;
            while (true)
            {
                try
                {
                    TcpClient = new TcpClie

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2020-10-23 13:32  TCP通讯\
     目录           0  2020-10-23 13:33  TCP通讯\client\
     目录           0  2020-10-23 13:32  TCP通讯\client\Backup\
     目录           0  2020-10-23 13:32  TCP通讯\client\Backup\client\
     文件        9911  2012-10-09 11:40  TCP通讯\client\Backup\client\Form1.Designer.cs
     文件        5346  2012-10-09 11:40  TCP通讯\client\Backup\client\Form1.cs
     文件        6203  2012-10-09 11:40  TCP通讯\client\Backup\client\Form1.resx
     文件         465  2012-10-09 11:40  TCP通讯\client\Backup\client\Program.cs
     目录           0  2020-10-23 13:32  TCP通讯\client\Backup\client\Properties\
     文件        1190  2012-10-09 11:40  TCP通讯\client\Backup\client\Properties\AssemblyInfo.cs
     文件        2866  2012-10-09 11:40  TCP通讯\client\Backup\client\Properties\Resources.Designer.cs
     文件        5612  2012-10-09 11:40  TCP通讯\client\Backup\client\Properties\Resources.resx
     文件        1089  2012-10-09 11:40  TCP通讯\client\Backup\client\Properties\Settings.Designer.cs
     文件         249  2012-10-09 11:40  TCP通讯\client\Backup\client\Properties\Settings.settings
     文件        3330  2012-10-09 11:40  TCP通讯\client\Backup\client\client.csproj
     文件         168  2012-10-09 11:40  TCP通讯\client\Backup\client\client.csproj.user
     文件         907  2012-10-09 11:40  TCP通讯\client\Backup\client.sln
     文件       17408  2012-10-09 11:40  TCP通讯\client\Backup\client.suo
     目录           0  2020-10-23 13:33  TCP通讯\client\Backup1\
     目录           0  2020-10-23 13:33  TCP通讯\client\Backup1\client\
     文件        9870  2012-10-11 13:31  TCP通讯\client\Backup1\client\Form1.Designer.cs
     文件        5334  2012-11-09 17:32  TCP通讯\client\Backup1\client\Form1.cs
     文件        6185  2012-10-11 22:24  TCP通讯\client\Backup1\client\Form1.resx
     文件         465  2012-10-09 11:40  TCP通讯\client\Backup1\client\Program.cs
     目录           0  2020-10-23 13:33  TCP通讯\client\Backup1\client\Properties\
     文件        1190  2012-10-09 11:40  TCP通讯\client\Backup1\client\Properties\AssemblyInfo.cs
     文件        2836  2012-10-09 11:40  TCP通讯\client\Backup1\client\Properties\Resources.Designer.cs
     文件        5612  2012-10-09 11:40  TCP通讯\client\Backup1\client\Properties\Resources.resx
     文件        1104  2012-10-09 11:40  TCP通讯\client\Backup1\client\Properties\Settings.Designer.cs
     文件         249  2012-10-09 11:40  TCP通讯\client\Backup1\client\Properties\Settings.settings
     文件        3538  2012-10-09 11:40  TCP通讯\client\Backup1\client\client.csproj
............此处省略132个文件信息

评论

共有 条评论