-
大小: 124KB文件類型: .rar金幣: 2下載: 1 次發(fā)布日期: 2021-06-12
- 語(yǔ)言: C#
- 標(biāo)簽: 遠(yuǎn)程監(jiān)控??網(wǎng)絡(luò)??
資源簡(jiǎn)介
源代碼中包含三個(gè)模塊,使用Recive和WhileSend可以實(shí)現(xiàn)遠(yuǎn)程桌面監(jiān)控,局域網(wǎng)中兩臺(tái)機(jī)器可以測(cè)試,使用Recive和Send可以實(shí)現(xiàn)圖片傳輸;

代碼片段和文件信息
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.IO;
using?System.Threading;
namespace?Recive
{
????public?partial?class?Form1?:?Form
????{
????????public?delegate?void?Complete();
????????public?event?Complete?finish;
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????private?void?Form1_Load(object?sender?EventArgs?e)
????????{
????????????this.FormBorderstyle?=?FormBorderstyle.None;
????????????WindowState?=?FormWindowState.Maximized;
????????????//為了不使主窗口線程阻塞
????????????//在窗體的加載事件中創(chuàng)建一個(gè)線程專門用來(lái)接收?qǐng)D片
????????????Control.CheckForIllegalCrossThreadCalls?=?true;
????????????Thread?th?=?new?Thread(new?ThreadStart(RC));
????????????th.Start();???????????
????????}
????????public?void?RC()
????????{
????????????/************************************************************************/
????????????/*?接收方為服務(wù)器端監(jiān)聽等待客戶端發(fā)送圖片并作顯示????????????????????*/
????????????/************************************************************************/
????????????Socket?sock?=?new?Socket(AddressFamily.InterNetwork?SocketType.Stream?ProtocolType.Tcp);
????????????EndPoint?point?=?new?IPEndPoint(IPAddress.Any?10000);
????????????sock.Bind(point);
????????????sock.Listen(10);?????????
??????????
????????????while?(true)
????????????{
????????????????Socket?client?=?sock.Accept();????????????????
????????????????byte[]?bitLen=new?byte[8];
????????????????client.Receive(bitLenbitLen.LengthSocketFlags.None);
????????????????//第一步接收文件的大小
????????????????long?contentLen?=?BitConverter.ToInt64(bitLen0);
????????????????int?size?=?0;
????????????????MemoryStream?ms?=?new?MemoryStream();
????????????????//循環(huán)接收文件的內(nèi)容如果接收完畢則break;
????????????????while?(size ????????????????{
????????????????????//分多次接收每次接收256個(gè)字節(jié)
????????????????????byte[]?bits?=?new?byte[256];
????????????????????int?r?=?client.Receive(bits?bits.Length?SocketFlags.None);
????????????????????if?(r?<=?0)?break;
????????????????????ms.Write(bits0r);??????????????????
????????????????????size?+=?r;
????????????????}
????????????????client.Close();
????????????????//接收到就顯示然后關(guān)閉當(dāng)前連接繼續(xù)監(jiān)聽
????????????????wangle(ms);
????????????}
???????????
????????}
????????public?void?wangle(MemoryStream?ms)
????????{
????????????Image?img?=?Image.FromStream(ms);
????????????picBox.Image?=?null;
????????????picBox.Image?=?img;
????????}
????????private?void?Form1_FormClosed(object?sender?FormClosedEventArgs?e)
????????{
????????????System.Environment.Exit(0);
????????}
????????private?void?picBox_Click(object?sender?EventArgs?e)
????????{
????????}
????????private?void?picBox_MouseDoubleClick(object?sender?MouseEventArgs?e)
????????{
????????????if?(WindowState?==?FormWindowState.Maximized)
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????????117??2013-11-01?10:38??Recive\app.config
?????文件??????10240??2013-11-06?14:39??Recive\bin\Debug\Recive.exe
?????文件????????117??2013-11-01?10:38??Recive\bin\Debug\Recive.exe.config
?????文件??????22016??2013-11-06?14:39??Recive\bin\Debug\Recive.pdb
?????文件??????11608??2013-11-06?14:25??Recive\bin\Debug\Recive.vshost.exe
?????文件????????117??2013-11-01?10:38??Recive\bin\Debug\Recive.vshost.exe.config
?????文件????????490??2010-03-17?22:39??Recive\bin\Debug\Recive.vshost.exe.manifest
?????文件???????3790??2013-11-06?14:34??Recive\Form1.cs
?????文件???????2594??2013-11-06?14:31??Recive\Form1.Designer.cs
?????文件???????5817??2013-11-06?14:31??Recive\Form1.resx
?????文件????????789??2013-11-04?10:27??Recive\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????6083??2013-11-06?14:39??Recive\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????920??2013-11-06?14:39??Recive\obj\x86\Debug\Recive.csproj.FileListAbsolute.txt
?????文件????????847??2013-11-06?14:39??Recive\obj\x86\Debug\Recive.csproj.GenerateResource.Cache
?????文件??????10240??2013-11-06?14:39??Recive\obj\x86\Debug\Recive.exe
?????文件????????180??2013-11-06?14:39??Recive\obj\x86\Debug\Recive.Form1.resources
?????文件??????22016??2013-11-06?14:39??Recive\obj\x86\Debug\Recive.pdb
?????文件????????180??2013-11-06?14:39??Recive\obj\x86\Debug\Recive.Properties.Resources.resources
?????文件???????4608??2013-11-01?11:09??Recive\obj\x86\Debug\TempPE\Properties.Resources.Designer.cs.dll
?????文件????????487??2013-10-31?15:27??Recive\Program.cs
?????文件???????1344??2013-10-31?15:27??Recive\Properties\AssemblyInfo.cs
?????文件???????2852??2013-11-01?10:38??Recive\Properties\Resources.Designer.cs
?????文件???????5612??2013-10-31?15:27??Recive\Properties\Resources.resx
?????文件???????1106??2013-11-01?10:38??Recive\Properties\Settings.Designer.cs
?????文件????????249??2013-10-31?15:27??Recive\Properties\Settings.settings
?????文件???????3743??2013-11-01?15:18??Recive\Recive.csproj
?????文件????????117??2013-11-01?10:37??Send\app.config
?????文件??????10752??2013-11-06?14:39??Send\bin\Debug\Send.exe
?????文件????????117??2013-11-01?10:37??Send\bin\Debug\Send.exe.config
?????文件??????22016??2013-11-06?14:39??Send\bin\Debug\Send.pdb
............此處省略78個(gè)文件信息
評(píng)論
共有 條評(píng)論