C#实现远程控制及桌面监控功能(服务端)
2013-06-27 10:34
701 查看
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.IO;
using System.Drawing.Imaging;
using System.Net;
using System.Net.Sockets;
namespace TestOnlineTeather
{
public partial class Form1 : Form
{
string pro = "{0}&{1}&{2}&{3}&{4}";//我的软件的协传输议
string userName = Dns.GetHostName();// 获取我的主机名
IPAddress ip;//我的ip
int port = 9305;//我的端口号
IPAddress stuIp; //学生的广播ip
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
if (MessageBox.Show("结束学生考试?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
{
//结束
UdpSendMsg(stuIp, "2", "结束");
}
}
public void UdpSendMsg(IPAddress sendIp, string cmdNo, string msg)
{
Socket client = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
//发送的内容
string context = string.Format(pro, userName,
ip.ToString(), DateTime.Now.Ticks, cmdNo, msg);
byte[] buffer = Encoding.Default.GetBytes(context);
//发给谁
client.Connect(sendIp, port);
//发送
client.Send(buffer);
client.Close();
}
private void button1_Click(object sender, EventArgs e)
{
//考试
UdpSendMsg(stuIp, "1", "考试");
Thread.Sleep(500);
//接收广播*************************
Thread th = new Thread(new ThreadStart(ReciveData));
th.IsBackground = true;
th.Start();
}
public void ReciveData()
{
IPAddress ip = IPAddress.Any;
Socket server = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
EndPoint ipe = new IPEndPoint(ip, port);
server.Bind(ipe);
byte[] buffer = new byte[60000];
//int width=Screen.PrimaryScreen .Bounds .Width;
//int height=Screen.PrimaryScreen.Bounds.Height;
while (true)
{
// Bitmap bmp = new Bitmap(width, height);
MemoryStream ms = new MemoryStream();
int len = server.Receive(buffer);
ms.Write(buffer, 0, len);
while (true)
{
if (len == 1 && buffer[0] == 100)
{
break;
}
len = server.Receive(buffer);
ms.Write(buffer, 0, len);
}
//流里面存放了一个图片的所有字节
Bitmap bmp = new Bitmap(ms);
pictureBox1.Image = bmp;
}
}
private void Form1_Load(object sender, EventArgs e)
{
#region //****************初始化用户信息
string hostName = Dns.GetHostName();
IPAddress[] ips = Dns.GetHostAddresses(hostName);
foreach (IPAddress item in ips)
{
if (!item.IsIPv6LinkLocal)
{
ip = item;
}
}
string t=textBox1.Text ;
stuIp = IPAddress.Parse("192.168." + t + ".255");
#endregion //*********************************
}
}
}
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.IO;
using System.Drawing.Imaging;
using System.Net;
using System.Net.Sockets;
namespace TestOnlineTeather
{
public partial class Form1 : Form
{
string pro = "{0}&{1}&{2}&{3}&{4}";//我的软件的协传输议
string userName = Dns.GetHostName();// 获取我的主机名
IPAddress ip;//我的ip
int port = 9305;//我的端口号
IPAddress stuIp; //学生的广播ip
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
if (MessageBox.Show("结束学生考试?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
{
//结束
UdpSendMsg(stuIp, "2", "结束");
}
}
public void UdpSendMsg(IPAddress sendIp, string cmdNo, string msg)
{
Socket client = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
//发送的内容
string context = string.Format(pro, userName,
ip.ToString(), DateTime.Now.Ticks, cmdNo, msg);
byte[] buffer = Encoding.Default.GetBytes(context);
//发给谁
client.Connect(sendIp, port);
//发送
client.Send(buffer);
client.Close();
}
private void button1_Click(object sender, EventArgs e)
{
//考试
UdpSendMsg(stuIp, "1", "考试");
Thread.Sleep(500);
//接收广播*************************
Thread th = new Thread(new ThreadStart(ReciveData));
th.IsBackground = true;
th.Start();
}
public void ReciveData()
{
IPAddress ip = IPAddress.Any;
Socket server = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
EndPoint ipe = new IPEndPoint(ip, port);
server.Bind(ipe);
byte[] buffer = new byte[60000];
//int width=Screen.PrimaryScreen .Bounds .Width;
//int height=Screen.PrimaryScreen.Bounds.Height;
while (true)
{
// Bitmap bmp = new Bitmap(width, height);
MemoryStream ms = new MemoryStream();
int len = server.Receive(buffer);
ms.Write(buffer, 0, len);
while (true)
{
if (len == 1 && buffer[0] == 100)
{
break;
}
len = server.Receive(buffer);
ms.Write(buffer, 0, len);
}
//流里面存放了一个图片的所有字节
Bitmap bmp = new Bitmap(ms);
pictureBox1.Image = bmp;
}
}
private void Form1_Load(object sender, EventArgs e)
{
#region //****************初始化用户信息
string hostName = Dns.GetHostName();
IPAddress[] ips = Dns.GetHostAddresses(hostName);
foreach (IPAddress item in ips)
{
if (!item.IsIPv6LinkLocal)
{
ip = item;
}
}
string t=textBox1.Text ;
stuIp = IPAddress.Parse("192.168." + t + ".255");
#endregion //*********************************
}
}
}
相关文章推荐
- C#实现简单远程控制及桌面监控功能(客户端)
- 第一页(服务端) :远程资源管理器 c#应用源代码,SERVICE + CLIENT 模式 可实现远程文件管理,下载功能
- 第二页(服务端) :远程资源管理器 c#应用源代码,SERVICE + CLIENT 模式 可实现远程文件管理,下载功能
- 使用tinymini210开发远程的温度监控系统,实现C#和安卓客户端显示数据和控制
- C#调用RDP,实现远程桌面共享及控制
- C# 实现设置桌面背景图片的功能
- 远程监控--(局域网版)1.C#实现网段扫描
- 远程控制桌面,手机外网远程桌面连接内网的实现过程,详细图文并茂
- 【原创】C#实现视频远程监控(下载)
- MQTT是IBM开发的一个即时通讯协议,构建于TCP/IP协议上,是物联网IoT的订阅协议,借助消息推送功能,可以更好地实现远程控制
- 配置agent向服务端发送数据,并实现监控功能
- Android L集成新特性之恢复出厂设置保护之如何实现,类似苹果ID的远程控制功能
- 小白虎远程控制软件待实现功能以及用户反馈! 请大家及时反馈需要完善的地方!
- 利用远程桌面连接实现外网对局域网计算机的控制
- 使用C#+Web+硬件实现远程控制的实现(物联网通信)
- C#实现远程关机功能(windows和linux)
- c# 实现端口转发可以用来实现远程桌面连接内网主机
- VC下远程控制(桌面)的完整实现
- 利用微软com组件mstscax.dll实现window7远程桌面功能
- VS2010中C#实现远程调试功能(转)