找传奇、传世资源到传世资源站!

tcp 远程桌面实例源码

  • 资源分类:C#网络编程
  • 发 布 人:房东的猫
  • 文件大小:440402
  • 文件格式:.rar
  • 浏览次数:34
  • 下载次数: 1
  • 发布时间:9月5日

  • 标签:
8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

tcp 远程桌面实例源码 C#网络编程-第1张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 TCPCommunication;namespace RemoteDeskClient{ public partial class Form1 : Form { TCPClientSocket _tcpClientSocket; TCPClientSender _tcpClientSender; MyDataClientAnalyse _myDataClientAnalyse; MyDataClientDeal _myDataClientDeal; GlobalHook _gloabalhook; System.Threading.Timer _timer; bool _monitor = false; //监控状态 public Form1() { InitializeComponent(); _tcpClientSocket = new TCPClientSocket(); _tcpClientSender = new TCPClientSender(_tcpClientSocket); _myDataClientAnalyse = new MyDataClientAnalyse(_tcpClientSocket); _myDataClientDeal = new MyDataClientDeal(_myDataClientAnalyse); _timer = new System.Threading.Timer(new TimerCallback(TimerCallBack), null, 0, 100); _tcpClientSocket.ConnectResponsed = new ConnectResponsedEventHandler(_tcpClientSocket_ConnectResponsed); _tcpClientSocket.DisConnected = new DisConnectedEventHandler(_tcpClientSocket_DisConnected); _myDataClientDeal.SimulateKeybdDown = new SimulateKeybdDownEventHandler(_myDataClientDeal_SimulateKeybdDown); _myDataClientDeal.SimulateKeybdUp = new SimulateKeybdUpEventHandler(_myDataClientDeal_SimulateKeybdUp); _myDataClientDeal.SimulateMouseLeftDown = new SimulateMouseLeftDownEventHandler(_myDataClientDeal_SimulateMouseLeftDown); _myDataClientDeal.SimulateMouseLeftUp = new SimulateMouseLeftUpEventHandler(_myDataClientDeal_SimulateMouseLeftUp); _myDataClientDeal.SimulateMouseMove = new SimulateMouseMoveEventHandler(_myDataClientDeal_SimulateMouseMove); _myDataClientDeal.SimulateMouseRightDown = new SimulateMouseRightDownEventHandler(_myDataClientDeal_SimulateMouseRightDown); _myDataClientDeal.SimulateMouseRightUp = new SimulateMouseRightUpEventHandler(_myDataClientDeal_SimulateMouseRightUp); _myDataClientDeal.SimulateMouseWheel = new SimulateMouseWheelEventHandler(_myDataClientDeal_SimulateMouseWheel); _myDataClientDeal.StartMonitor = new StartMonitorEventHandler(_myDataClientDeal_StartMonitor); _myDataClientDeal.StopMonitor = new StopMonitorEventHandler(_myDataClientDeal_StopMonitor); //钩子消耗系统性能 注销掉钩子代码后 服务端无法监控鼠标和键盘输入信息 //_gloabalhook = new GlobalHook(); //_gloabalhook.KeyDown = new KeyEventHandler(_gloabalhook_KeyDown); //_gloabalhook.KeyUp = new KeyEventHandler(_gloabalhook_KeyUp); //_gloabalhook.OnMouseActivity = new MouseEventHandler(_gloabalhook_OnMouseActivity); _myDataClientDeal.Start(); } #region socket状态 void _tcpClientSocket_ConnectResponsed(System.Net.EndPoint remoteEP, bool result) { if (result) { _monitor = true; } } void _tcpClientSocket_DisConnected() { _monitor = false; } #endregion #region 钩子 void _gloabalhook_OnMouseActivity(object sender, MouseEventArgs e) { if (_monitor) { if (e.Button == MouseButtons.Left) { _tcpClientSender.SendString(Msg.ZMsg5, ""); //左键按下 _tcpClientSender.SendString(Msg.ZMsg6, ""); //左键松开 } if (e.Button == MouseButtons.Right) { _tcpClientSender.SendString(Msg.ZMsg7, ""); //右键按下 _tcpClientSender.SendString(Msg.ZMsg8, ""); //右键松开 } if (e.Button == MouseButtons.None && e.Delta == 0) { _tcpClientSender.SendString(Msg.ZMsg4, e.X " " e.Y); //鼠标位置 } //if (e.Delta == 0) //{ // _tcpClientSender.SendString(Msg.ZMsg9, e.Delta.ToString()); //鼠标滚动 //} } } void _gloabalhook_KeyUp(object sender, KeyEventArgs e) { if (_monitor) { _tcpClientSender.SendString(Msg.ZMsg3, e.KeyData.ToString()); } } void _gloabalhook_KeyDown(object sender, KeyEventArgs e) { if (_monitor) { _tcpClientSender.SendString(Msg.ZMsg2, e.KeyData.ToString()); } } #endregion #region 数据处理 void _myDataClientDeal_StopMonitor(string extrainfo, string remoteIP, int remotePort) { _monitor = false; } void _myDataClientDeal_StartMonitor(string extrainfo, string remoteIP, int remotePort) { _monitor = true; } void _myDataClientDeal_SimulateMouseWheel(string mouseinfo, string remoteIP, int remotePort) { string[] infos = mouseinfo.Split(' '); NativeMethods.MouseWheel(int.Parse(infos[2]), int.Parse(infos[0]), int.Parse(infos[1])); } void _myDataClientDeal_SimulateMouseRightUp(string mouseinfo, string remoteIP, int remotePort) { string[] infos = mouseinfo.Split(' '); NativeMethods.MouseRightUp(int.Parse(infos[0]), int.Parse(infos[1])); } void _myDataClientDeal_SimulateMouseRightDown(string mouseinfo, string remoteIP, int remotePort) { string[] infos = mouseinfo.Split(' '); NativeMethods.MouseRigthDown(int.Parse(infos[0]), int.Parse(infos[1])); } void _myDataClientDeal_SimulateMouseMove(string mouseinfo, string remoteIP, int remotePort) { string[] infos = mouseinfo.Split(' '); NativeMethods.MouseMove(int.Parse(infos[0]), int.Parse(infos[1])); } void _myDataClientDeal_SimulateMouseLeftUp(string mouseinfo, string remoteIP, int remotePort) { string[] infos = mouseinfo.Split(' '); NativeMethods.MouseLeftUp(int.Parse(infos[0]), int.Parse(infos[1])); } void _myDataClientDeal_SimulateMouseLeftDown(string mouseinfo, string remoteIP, int remotePort) { string[] infos = mouseinfo.Split(' '); NativeMethods.MouseLeftDown(int.Parse(infos[0]), int.Parse(infos[1])); } void _myDataClientDeal_SimulateKeybdUp(string keyinfo, string remoteIP, int remotePort) { NativeMethods.KeybdUp(keyinfo); } void _myDataClientDeal_SimulateKeybdDown(string keyinfo, string remoteIP, int remotePort) { NativeMethods.KeybdDown(keyinfo); } #endregion #region 屏幕截图 private void TimerCallBack(object obj) { if (_monitor) { Bitmap b = PrintSystemScreen(); _tcpClientSender.SendObject(Msg.ZMsg1, b); } } #endregion private void Form1_Load(object sender, EventArgs e) { } private Bitmap PrintSystemScreen() { Bitmap bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); Graphics screenG = Graphics.FromImage(bmp); screenG.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy); return bmp; } private void button1_Click(object sender, EventArgs e) { _tcpClientSocket.Start(textBox1.Text, 9999); } }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复