Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Data;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Net;
- using System.Net.Sockets;
- using System.Threading;
- using System.Text;
- using System.Windows.Interop;
- namespace AndAnotherBackend
- {
- /// <summary>
- /// Interaction logic for App.xaml
- /// </summary>
- public partial class App : Application
- {
- TcpListener server = null;
- public void SocketServer()
- {
- Int32 Port = 11000;
- IPAddress addr = IPAddress.Parse("0.0.0.0");
- server = new TcpListener(addr, Port);
- server.Start();
- Byte[] bytes = new Byte[256];
- String data = null;
- while (true)
- {
- Console.Write("Waiting for a connection... ");
- TcpClient client = server.AcceptTcpClient();
- Console.WriteLine("Connected!");
- NetworkStream stream = client.GetStream();
- int i;
- while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
- {
- data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
- Console.WriteLine("Received: {0}", data);
- MessageBox.Show(data);
- data = data.ToUpper();
- byte[] msg = System.Text.Encoding.ASCII.GetBytes(data);
- stream.Write(msg, 0, msg.Length);
- Console.WriteLine("Sent: {0}", data);
- }
- client.Close();
- }
- }
- public String AskPy(string cmd) {
- // Here we build a TCP connection with the Python backend
- TcpClient client = new TcpClient();
- client.Connect(IPAddress.Loopback, 11001);
- NetworkStream stream = client.GetStream();
- byte[] msg = System.Text.Encoding.ASCII.GetBytes(cmd);
- stream.Write(msg, 0, msg.Length);
- byte[] bytes = new byte[256];
- String data = null;
- int i = stream.Read(bytes, 0, bytes.Length);
- data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
- client.Close();
- return data;
- }
- public App()
- {
- MainWindow holder = new MainWindow();
- holder.Loaded += (sender, e) =>
- {
- holder.Hide();
- holder.WindowState = WindowState.Minimized;
- holder.ShowInTaskbar = false;
- Thread t = new Thread(new ThreadStart(SocketServer));
- t.Start();
- int ScreenAmount = int.Parse(AskPy("monitor_amount"));
- int NextMove = 0;
- for(int i = 0; i < ScreenAmount; i++) {
- string Sizes = AskPy("monitor_size " + i.ToString());
- string[] SizesArray = Sizes.Split('x');
- int width = int.Parse(SizesArray[0]);
- int height = int.Parse(SizesArray[1]);
- MainWindow CurrentWindow = new MainWindow();
- CurrentWindow.Title = "ScreenHelper" + i.ToString();
- CurrentWindow.Show();
- IntPtr Handle = new WindowInteropHelper(CurrentWindow).Handle;
- MoveWindow(Handle, NextMove, 0, width, height, true);
- NextMove += width;
- }
- holder.webView = null;
- holder.Content = null;
- };
- this.Run(holder);
- }
- [System.Runtime.InteropServices.DllImport("user32.dll")]
- public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
- [System.Runtime.InteropServices.DllImport("user32.dll")]
- public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement