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

资源简介

vs2010开发,可以找到解决方案直接运行。

资源截图

代码片段和文件信息

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

namespace ClientServer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Socket socket;
        private void btStart_Click(object sender EventArgs e)
        {
            try
            {
                socket = new Socket(AddressFamily.InterNetwork SocketType.Stream ProtocolType.Tcp);
                IPAddress ip = IPAddress.Parse(tb1.Text);
                IPEndPoint point = new IPEndPoint(ip Convert.ToInt32(tb2.Text));
                socket.Connect(point);
                if (socket.IsBound)
                {
                    ShowMsg(“连接成功“);
                }
                Thread th = new Thread(Receive);
                th.IsBackground = true;
                th.Start();
            }
            catch { }
           
        }
        private void ShowMsg(string str) 
        {
            tbx1.AppendText(str + “\r\n“);
        }

        private void btSend_Click(object sender EventArgs e)
        {
            try
            {
                string str = tbx2.Text.ToString().Trim();

                byte[] buffer = System.Text.Encoding.UTF8.GetBytes(str);

                socket.Send(buffer);
                tbx2.Text = ““;
                ShowMsg(“我:“ + str);
            }
            catch { }
           
        }
        private void Receive() 
        {
            while (true) 
            {
                try 
                {
                    byte[] buffer = new byte[1024 * 1024 * 2];
                    int r = socket.Receive(buffer);
                    if (r == 0) { break; }
                    if(buffer[0]==0)
                    {
                      
                        string str = Encoding.UTF8.GetString(buffer 1 r-1);
                        ShowMsg(socket.RemoteEndPoint.ToString() + “:“ + str);
                    }else if(buffer[0]==1)
                    {
                        SaveFileDialog sfd = new SaveFileDialog();
                        sfd.InitialDirectory = @“C:\Users\Administrator\Desktop“;
                        sfd.title = “请选择保存的文件“;
                        sfd.Filter = “所有文件|*.*“;
                        sfd.ShowDialog(this);
                        string path = sfd.FileName;
                        using(FileStream fs=new FileStream(pathFileMode.OpenOrCreateFileAccess.Write))
                        {
                            fs.Write(buffer1r-1);

                        }
                        MessageBox.Show(“保存成功“);

                    }
                    else if (buffer[0] == 2)
                    {

                

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

     文件      11264  2015-04-24 20:45  网络编程\ClientServer\bin\Debug\ClientServer.exe

     文件      28160  2015-04-24 20:45  网络编程\ClientServer\bin\Debug\ClientServer.pdb

     文件      11600  2015-04-24 20:46  网络编程\ClientServer\bin\Debug\ClientServer.vshost.exe

     文件        490  2013-06-18 20:28  网络编程\ClientServer\bin\Debug\ClientServer.vshost.exe.manifest

     文件       3683  2015-04-24 18:44  网络编程\ClientServer\ClientServer.csproj

     文件       3601  2015-04-24 20:45  网络编程\ClientServer\Form1.cs

     文件       5202  2015-04-24 20:45  网络编程\ClientServer\Form1.Designer.cs

     文件       5817  2015-04-24 20:45  网络编程\ClientServer\Form1.resx

     文件        603  2015-04-24 20:46  网络编程\ClientServer\obj\x86\Debug\ClientServer.csproj.FileListAbsolute.txt

     文件        975  2015-04-24 20:45  网络编程\ClientServer\obj\x86\Debug\ClientServer.csproj.GenerateResource.Cache

     文件      11264  2015-04-24 20:45  网络编程\ClientServer\obj\x86\Debug\ClientServer.exe

     文件        180  2015-04-24 20:45  网络编程\ClientServer\obj\x86\Debug\ClientServer.Form1.resources

     文件      28160  2015-04-24 20:45  网络编程\ClientServer\obj\x86\Debug\ClientServer.pdb

     文件        180  2015-04-24 18:44  网络编程\ClientServer\obj\x86\Debug\ClientServer.Properties.Resources.resources

     文件       6326  2015-04-24 20:45  网络编程\ClientServer\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        493  2015-04-24 18:29  网络编程\ClientServer\Program.cs

     文件       1356  2015-04-24 18:29  网络编程\ClientServer\Properties\AssemblyInfo.cs

     文件       2876  2015-04-24 18:29  网络编程\ClientServer\Properties\Resources.Designer.cs

     文件       5612  2015-04-24 18:29  网络编程\ClientServer\Properties\Resources.resx

     文件       1099  2015-04-24 18:29  网络编程\ClientServer\Properties\Settings.Designer.cs

     文件        249  2015-04-24 18:29  网络编程\ClientServer\Properties\Settings.settings

     文件      12800  2015-04-24 20:46  网络编程\网络编程\bin\Debug\网络编程.exe

     文件      28160  2015-04-24 20:46  网络编程\网络编程\bin\Debug\网络编程.pdb

     文件      11600  2015-04-24 20:47  网络编程\网络编程\bin\Debug\网络编程.vshost.exe

     文件        490  2013-06-18 20:28  网络编程\网络编程\bin\Debug\网络编程.vshost.exe.manifest

     文件       4716  2015-04-24 20:46  网络编程\网络编程\Form1.cs

     文件       6795  2015-04-24 20:41  网络编程\网络编程\Form1.Designer.cs

     文件       5817  2015-04-24 20:41  网络编程\网络编程\Form1.resx

     文件       2867  2015-04-24 16:34  网络编程\网络编程\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6326  2015-04-24 20:46  网络编程\网络编程\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

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

评论

共有 条评论

相关资源