8wDlpd.png
8wDFp9.png
8wDEOx.png
8wDMfH.png
8wDKte.png

基于CHROME的现场远程控制

dfeva 2月前

109 0

我想远程管理用户打开的浏览器窗口,以便支持我的网站上的用户。我通过套接字传输点击和键盘事件来模拟一些事件,但由于浏览器

我想远程管理用户打开的浏览器窗口,以便支持我的网站上的用户。

我通过套接字传输点击和键盘事件模拟了一些事件,但由于浏览器策略,我无法访问所有事件。例如,当我想打开颜色选择器时,我收到了一条警告消息。

    function triggerClickEvent(clickPosition) {
        var { x, y } = clickPosition;
        if (!window.clickEvent) {
            window.clickEvent = new MouseEvent('click', {
                view: window,
                bubbles: true,
                button: 1,
                cancelable: true,
                clientX: x,
                clientY: y
            });
        } else {
            window.clickEvent.clientX = x;
            window.clickEvent.clientY = y;
        }
        document.elementFromPoint(x, y).dispatchEvent(clickEvent);
        clickEvent.target.blur();
        clickEvent.target.focus();
        clickEvent.target.click();
    }
    function triggerKeyPressEvent(keyPress) {
        var keyPressEvent = new KeyboardEvent('keydown', { 'key': keyPress.key });
        document.dispatchEvent(keyPressEvent);
    }

如何通过获取相关的用户权限来解决这些问题?

帖子版权声明 1、本帖标题:基于CHROME的现场远程控制
    本站网址:http://xjnalaquan.com/
2、本网站的资源部分来源于网络,如有侵权,请联系站长进行删除处理。
3、会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。
4、本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
5、站长邮箱:yeweds@126.com 除非注明,本帖由dfeva在本站《sockets》版块原创发布, 转载请注明出处!
最新回复 (0)
  • 我正在寻找韩国杂货市场的地址。- 英文:Schaumburg 的 Joong boo 市场- 韩语:使用英语搜索结果是正确的,但使用韩语搜索结果是

    我正在寻找韩国杂货市场的地址。- 英文:Schaumburg 的 Joong boo 市场- 韩语:用英文搜索的结果是正确的,但用韩语搜索的结果是错误的。(用韩语搜索实际上会出现不同的市场地址)

    我要求为该企业创建商业档案,并确认档案已创建。但是搜索结果仍然是错误的。

  • 我对 Python 还很陌生,所以我的代码看起来有点简单。我有一个真空室,我可以通过 TCP 命令与之通信。我现在的目标是在一个图表上绘制压力,然后

    我对 Python 还很陌生,所以我确信我的代码看起来有点初级。我有一个真空室,我可以通过 TCP 命令与之通信。我现在的目标是在一张图上绘制压力,在另一张图上绘制热电偶温度。我可以很好地进行通信并很好地读回数据,我可以将实时数据绘制到第二张图中,但是当我尝试将数据绘制到第一张图中时,它没有显示。

    import socket
    import sys
    import time
    import binascii 
    import matplotlib
    import numpy as np
    import matplotlib.pyplot as plt
    from matplotlib import animation
    from matplotlib.animation import FuncAnimation
    from datetime import datetime
    matplotlib.use('Qt5Agg')
    
    #TVAC IP and Port
    target_host = "10.1.2.101"
    target_port = 1
    
    print()
    
    #trying to open a TCP socket
    try:
        client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        client.connect((target_host,target_port))
    except socket.error:
        print("Socket Not Created!  ¯\(°_o)/¯")
        sys.exit()
    print("Socket Created   (⌐⊙_⊙)")
    print()
    print("Socket Connected To " + target_host)
    print()
    
    time.sleep(2)
    
    Pressure, TC0, TC1, TC2, TC3, TC4, TC5, TC6, TC7 = "?VP", "?T2", "?T12", "?T13", "?T14", "?T15", "?T16", "?T17", "?T18"
    
    #carriage return
    CR = "\r"
    
    def TVAC(cmd):
    
        try:
            #send command and receive data ex/ VP:3.23e-07\r
            client.send(bytes(cmd + CR  + '\0','ascii'))
            response = client.recv(1024).decode('ascii')
            if (cmd == '?VP'):
                response4 = float(response[3:-1])
                response5 = format(response4, '.000000000008f')
            else:
                response2 = response[5:-1]
                response3 = float(response2)
                response5 = np.divide(response3, 10)
            response6 = float(response5)
            print(response6)
            
        except socket.error:
            print("Failed to send command")
        return response6
    
    #animate the data on a plot graph
    
    fig = plt.figure()
    axis1 = fig.add_subplot(211)
    axis2 = fig.add_subplot(212)
    
    #figure, (axis1, axis2) = plt.subplots(2)
    
    x_data, y_data = [], []
    x_data1, y_data2, y_data3, y_data4, y_data5, y_data6, y_data7, y_data8, y_data9 = [], [], [], [], [], [], [], [], []
    
    line1, = axis1.plot_date(x_data, y_data, "-", color='red')
    line2, = axis2.plot_date(x_data1, y_data2, "-", color='blue')
    line3, = axis2.plot_date(x_data1, y_data3, "-", color='green')
    line4, = axis2.plot_date(x_data1, y_data4, "-", color='purple')
    line5, = axis2.plot_date(x_data1, y_data5, "-", color='yellow')
    line6, = axis2.plot_date(x_data1, y_data6, "-", color='black')
    line7, = axis2.plot_date(x_data1, y_data7, "-", color='orange')
    line8, = axis2.plot_date(x_data1, y_data8, "-", color='grey')
    line9, = axis2.plot_date(x_data1, y_data9, "-", color='red')
    line = [line1, line2, line3, line4, line5, line6, line7, line8, line9]
    
    axis1.grid(axis = 'y')
    axis2.grid(axis = 'y')
    
    def update(frame):
    
        xdata = datetime.now()
        xdata1 = datetime.now()
     
        ydata = TVAC(Pressure)
        ydata1 = TVAC(TC0)
        ydata2 = TVAC(TC1)
        ydata3 = TVAC(TC2)
        ydata4 = TVAC(TC3)
        ydata5 = TVAC(TC4)
        ydata6 = TVAC(TC5)
        ydata7 = TVAC(TC6)
        ydata8 = TVAC(TC7)
     
        x_data.append(xdata)
        x_data1.append(xdata1)
        
        y_data.append(ydata)
        y_data2.append(ydata1)
        y_data3.append(ydata2)
        y_data4.append(ydata3)
        y_data5.append(ydata4)
        y_data6.append(ydata5)
        y_data7.append(ydata6)
        y_data8.append(ydata7)
        y_data9.append(ydata8)
        
        #axis1.plot(x_data, y_data)
        
        line[0].set_data(x_data, y_data)
        line[1].set_data(x_data1, y_data2)
        line[2].set_data(x_data1, y_data3)
        line[3].set_data(x_data1, y_data4)
        line[4].set_data(x_data1, y_data5)
        line[5].set_data(x_data1, y_data6)
        line[6].set_data(x_data1, y_data7)
        line[7].set_data(x_data1, y_data8)
        line[8].set_data(x_data1, y_data9)
      
        axis1.set_title("Pressure")
        axis2.set_title("Temperature")
        
        fig.gca().relim()
        axis1.ticklabel_format(axis='y',style='sci',scilimits=(0,0))
        axis2.ticklabel_format(axis='y',style='plain',scilimits=(0,0))
        fig.gca().autoscale_view()
     
        return line,
    
    anim = FuncAnimation(fig, update, cache_frame_data=False)
    plt.show()
    

    我已将代码更改为显示 3 个图表,以证明这只是我可以绘制的最后一个图表,情况似乎确实如此。我确信这是一个简单的修复,但我现在完全陷入困境。任何帮助都将不胜感激,谢谢!

  • 因此,我创建了一个简单的服务器,它使用 ServerSocket 接受来自浏览器的连接。当浏览器连接时,它会运行一个新线程 (ClientHandler) 来处理该连接。在 clientHandler 中,它

    所以我创建了一个简单的服务器,它使用 ServerSocket 接受来自浏览器的连接。当浏览器连接时,它会运行一个新线程 (ClientHandler) 来处理该连接。在 clientHandler 中,它响应 GET 请求并提交一个 html 页面。该页面只有 1 个按钮,用于发送值为“Hello from browser”的 POST 请求,这是使用 AJAX 完成的,因此页面不会刷新。每次我发送 POST 请求时,它都会与套接字建立新连接,但响应中的连接是否保持活动状态?

    import java.io.*;
    import java.net.*;
    
    public class Server {
        private static final int PORT = 8080;
        private static int count = 0;
        private static final String HTML_FILE_PATH = "src/main/java/org/example/index.html";
    
        public static void main(String[] args) throws Exception {
            try (ServerSocket serverSocket = new ServerSocket(PORT)) {
                System.out.println("Server started on port " + PORT);
    
                while (true) {
                    try {
                        Socket clientSocket = serverSocket.accept();
                        System.out.println("Client: " + ++count + " Joined");
                        ClientHandler clientHandler = new ClientHandler(clientSocket);
                        // Handle the client connection in a new thread 
                        new Thread(clientHandler).start();
                    } catch (IOException e) {
                        System.err.println("Error accepting client connection: " + e.getMessage());
                    }
                }
            }
        }
    }
    
    import java.io.*;
    import java.net.*;
    import java.nio.file.Files;
    import java.util.concurrent.atomic.AtomicInteger;
    
    public class ClientHandler implements Runnable {
        private static final AtomicInteger nextId = new AtomicInteger(0);
        private Socket clientSocket;
        private int clientId;
        private static final String HTML_FILE_PATH = "src/main/java/org/example/index.html";
    
        public ClientHandler(Socket clientSocket) {
            this.clientSocket = clientSocket;
            this.clientId = nextId.incrementAndGet();
        }
    
        @Override
        public void run() {
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
                 BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()))) {
    
                String line;
                StringBuilder requestBuilder = new StringBuilder();
                while (!(line = reader.readLine()).isBlank()) {
                    requestBuilder.append(line).append("\r\n");
                }
                String request = requestBuilder.toString();
                String[] requestLines = request.split("\r\n");
                String[] requestLine = requestLines[0].split(" ");
                String method = requestLine[0];
                String path = requestLine[1];
                if ("GET".equals(method) && "/".equals(path)) {
                    serveFile(HTML_FILE_PATH, writer);
                } else if ("POST".equals(method)) {
                    // Extract the Content-Length from the headers
                    int contentLength = getContentLength(requestLines);
                    char[] buffer = new char[contentLength];
    
                    // Read the POST data from the input stream
                    reader.read(buffer, 0, contentLength);
                    String postData = new String(buffer);
    
                    // Print the POST data in the server terminal
                    System.out.println("POST Data: " + postData);
    
                    // Continue with sending the response
                    String responseMessage = "Hello Client " + clientId + ", This is server.";
                    writeResponse(writer, "HTTP/1.1 200 OK", "text/plain", responseMessage.getBytes(), true);
                } else {
                    writeResponse(writer, "HTTP/1.1 404 Not Found", "text/plain", "Not Found".getBytes(), false);
                }
            } catch (IOException e) {
                System.err.println("Error handling client " + clientId + ": " + e.getMessage());
            }
        }
    
        private void serveFile(String filePath, BufferedWriter writer) throws IOException {
            File file = new File(filePath);
            if (file.exists()) {
                byte[] fileContent = Files.readAllBytes(file.toPath());
                writeResponse(writer, "HTTP/1.1 200 OK", "text/html", fileContent, true);
            } else {
                writeResponse(writer, "HTTP/1.1 404 Not Found", "text/plain", "File not found".getBytes(), false);
            }
        }
    
        private void writeResponse(BufferedWriter writer, String statusLine, String contentType, byte[] content, boolean keepAlive) throws IOException {
            writer.write(statusLine + "\r\n");
            writer.write("Content-Type: " + contentType + "\r\n");
            writer.write("Content-Length: " + content.length + "\r\n");
            if (keepAlive) {
                writer.write("Connection: keep-alive\r\n");
                writer.write("Keep-Alive: timeout=60, max=100\r\n");
            } else {
                writer.write("Connection: close\r\n");
            }
            writer.write("\r\n");
            writer.write(new String(content));
            writer.flush();
        }
        private int getContentLength(String[] requestHeaders) {
            for (String header : requestHeaders) {
                if (header.toLowerCase().startsWith("content-length:")) {
                    return Integer.parseInt(header.substring("content-length:".length()).trim());
                }
            }
            return 0;
        }
    }
    
    <!DOCTYPE html>
    <html>
    <head>
        <title>Tic-Tac-Toe</title>
    </head>
    <body>
    <button id="helloButton">Say Hello</button>
    <div id="responseText"></div>
    <script>
        document.getElementById('helloButton').onclick = function() {
            fetch('/', {
                method: 'POST',
                headers: {
                    'Content-Type': 'text/plain'
                },
                body: 'Hello from browser'
            })
                .then(response => response.text())
                .then(data => document.getElementById('responseText').innerText = data)
                .catch(error => console.error('Error:', error));
        };
    </script>
    </body>
    </html>
    

    我原本期望有持久连接,但发送多个 POST 请求时的输出如下。 开发工具中的 服务器终端

  • Windows(作为主机)和 Hyper-v 是否支持 virtio_tansport(virtio_vsocket)?如果支持,hyperv_transport(hv_socket) 相比 virtio_tansport(virtio_vsocket) 有哪些优势?如何选择

    Windows(作为主机)和 Hyper-v 是否支持 virtio_tansport(virtio_vsocket)?

    如果支持,hyperv_transport(hv_socket) 相对于 virtio_tansport(virtio_vsocket) 有哪些优势?

    如何选择使用virtio_transport还是hypver_transport?如果我使用Hyper-v,是否可以只选择hyperv_transport,或者也可以选择virtio_transport但是性能较差?如果我使用其他虚拟化平台(非Hyper-v),是否可以只选择virtio_transport?

    我们开发新的 vsocket 传输 - hypver_transport 的原因是什么?

    virtio_transport和hyperv_transport的传输机制不同,virtio_transport基于virtio,hyperv_transport是利用Windows虚拟化技术栈通过VMbus进行传输,当Windows作为Host,Linux/Android作为Guest时,Guest中的vsocket如何选择virtio_transport还是hyperv_transport?hyper-v和Windows是否都支持virtio_transport,还是只支持hyperv_transport?

  • 我叫 Luís,目前正在开发一个项目,该项目包括实施客户端/服务器系统来管理 ServiMoto 公司提供的移动服务。服务包括树木和...

    我叫 Luís,目前正在开发一个项目,该项目包括实施客户端/服务器系统来管理 ServiMoto 公司提供的移动服务。服务包括树木和花园检查、消防服务干预、邮政投递和披萨外送。该系统允许客户端(自行车)连接到服务器以接收任务、更新任务状态和请求新任务。服务器管理这些请求,将任务分配给客户端,并在 CSV 文件中保存分配的任务和客户端的记录。该项目使用套接字和定义的通信协议在 C# 中实现。

    目前我的两个主要代码是:

    类服务器:

    // Object Mutex to ensure exclusive access to CSV files
    static Mutex mutex = new Mutex();
    
    // Method to update the CSV file with the completion of a task
    static void UpdateCompletedTask(string fileName, string taskId)
    {
        // Locks the mutex to ensure exclusive access
        mutex.WaitOne();
        try
        {
            string[] lines = File.ReadAllLines(fileName);
            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].StartsWith(taskId))
                {
                    // Replaces "in progress" with "completed" only if "in progress" is present
                    if (lines[i].Contains("in progress"))
                    {
                        lines[i] = lines[i].Replace("in progress", "completed");
                    }
                    break;
                }
            }
            File.WriteAllLines(fileName, lines);
        }
        finally
        {
            // Releases the mutex
            mutex.ReleaseMutex();
        }
    }
    
    // Method to assign a new task to the client and update the corresponding CSV file
    static void AllocateNewTask(string fileName, string clientId)
    {
        // Locks the mutex to ensure exclusive access
        mutex.WaitOne();
        try
        {
            // Logic to assign a new task to the client and update the CSV file
            // For example, it may involve reading the file to find an available task and updating its status
        }
        finally
        {
            // Releases the mutex
            mutex.ReleaseMutex();
        }
    }
    
    // Server IP address and port
    IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
    int port = 8888;
    
    // Starts the server and listens for connections
    server = new TcpListener(ipAddress, port);
    server.Start();
    
    Console.WriteLine("Server started...");
    
    // Accepts client connection
    TcpClient client = server.AcceptTcpClient();
    Console.WriteLine("Client connected!");
    
    // Prepares network streams
    NetworkStream stream = client.GetStream();
    byte[] data = new byte[256];
    StringBuilder response = new StringBuilder();
    
    int bytesRead;
    
    // Reads data received from the client
    while ((bytesRead = stream.Read(data, 0, data.Length)) != 0)
    {
        response.Append(Encoding.ASCII.GetString(data, 0, bytesRead));
        Console.WriteLine("Received message: {0}", response.ToString());
    
        // Checks the type of received message
        if (response.ToString().StartsWith("CONNECT"))
        {
            // Responds with success
            byte[] msg = Encoding.ASCII.GetBytes("100 OK");
            stream.Write(msg, 0, msg.Length);
            Console.WriteLine("Response sent: 100 OK");
        }
        else if (response.ToString().StartsWith("TASK_COMPLETE"))
        {
            // Extracts the ID of the completed task
            string completedTaskId = response.ToString().Substring("TASK_COMPLETE".Length).Trim();
            // Updates the corresponding CSV file
            UpdateCompletedTask("Service_A.csv", completedTaskId);
            // Responds with task completion confirmation
            byte[] msg = Encoding.ASCII.GetBytes("TASK_COMPLETED");
            stream.Write(msg, 0, msg.Length);
            Console.WriteLine("Response sent: TASK_COMPLETED");
        }
        else if (response.ToString() == "REQUEST_TASK")
        {
            // Logic to assign a new task to the client and update the CSV file
            // Here you can call the AllocateNewTask() method to assign the new task
        }
        else if (response.ToString() == "QUIT")
        {
            // Responds with connection closure
            byte[] msg = Encoding.ASCII.GetBytes("400 BYE");
            stream.Write(msg, 0, msg.Length);
            Console.WriteLine("Response sent: 400 BYE");
    
            // Closes the connection
            client.Close();
            break;
        }
        else
        {
            // Responds with error
            byte[] msg = Encoding.ASCII.GetBytes("ERROR");
            stream.Write(msg, 0, msg.Length);
            Console.WriteLine("Response sent: ERROR");
        }
    
        // Clears the StringBuilder for the next message
        response.Clear();
    }
    
    

    现在客户端类:

    // Server IP address and port
    string serverIp = "127.0.0.1";
    int port = 8888;
    
    // Creates an instance of the TCP client
    TcpClient client = new TcpClient(serverIp, port);
    Console.WriteLine("Connected to server...");
    
    // Prepares network streams
    NetworkStream stream = client.GetStream();
    byte[] data = new byte[256];
    string response = string.Empty;
    
    Console.WriteLine("Enter your Client ID: ");
    string clientId = Console.ReadLine();
    
    // Sends connection message
    string connectMessage = "CONNECT";
    byte[] connectMsg = Encoding.ASCII.GetBytes(connectMessage);
    stream.Write(connectMsg, 0, connectMsg.Length);
    Console.WriteLine("Message sent: {0}", connectMessage);
    
    // Reads the server's response
    int bytesReceived = stream.Read(data, 0, data.Length);
    response = Encoding.ASCII.GetString(data, 0, bytesReceived);
    Console.WriteLine("Response received: {0}", response);
    
    while (true)
    {
        Console.WriteLine("Choose an option:");
        Console.WriteLine("1. Complete task");
        Console.WriteLine("2. Request new task");
        Console.WriteLine("3. Quit");
        Console.Write("Option: ");
        string option = Console.ReadLine();
    
        switch (option)
        {
            case "1":
                // Sends task completion message
                Console.WriteLine("Enter the ID of the completed task: ");
                string completedTaskId = Console.ReadLine();
                string completionMessage = $"TASK_COMPLETE <{completedTaskId}>";
                byte[] completionMsg = Encoding.ASCII.GetBytes(completionMessage);
                stream.Write(completionMsg, 0, completionMsg.Length);
                Console.WriteLine("Message sent: {0}", completionMessage);
    
                // Reads the server's response
                int completionBytesReceived = stream.Read(data, 0, data.Length);
                response = Encoding.ASCII.GetString(data, 0, completionBytesReceived);
                Console.WriteLine("Response received: {0}", response);
                break;
    
            case "2":
                // Sends request for new task
                string requestMessage = "REQUEST_TASK";
                byte[] requestMsg = Encoding.ASCII.GetBytes(requestMessage);
                stream.Write(requestMsg, 0, requestMsg.Length);
                Console.WriteLine("Message sent: {0}", requestMessage);
    
                // Reads the server's response
                int requestBytesReceived = stream.Read(data, 0, data.Length);
                response = Encoding.ASCII.GetString(data, 0, requestBytesReceived);
                Console.WriteLine("Response received: {0}", response);
                break;
    
            case "3":
                // Sends quit message
                string quitMessage = "QUIT";
                byte[] quitMsg = Encoding.ASCII.GetBytes(quitMessage);
                stream.Write(quitMsg, 0, quitMsg.Length);
                Console.WriteLine("Message sent: {0}", quitMessage);
    
                // Reads the server's response
                int quitBytesReceived = stream.Read(data, 0, data.Length);
                response = Encoding.ASCII.GetString(data, 0, quitBytesReceived);
                Console.WriteLine("Response received: {0}", response);
    
                // Closes the connection and exits the loop
                client.Close();
                return;
    
            default:
                Console.WriteLine("Invalid option.");
                break;
        }
    }
    
    

    问题是,当我想使用 UpdateCompletedTask 函数声明任务完成时,csv 文件不会改变,始终保持不变。有人能帮帮我吗?

    我多次更改了函数的代码,因为我认为问题出在 UpdateCompletedTask 函数中,但仍然没有任何变化。

  • 您的服务器不支持保持活动。它读取一个请求并发送一个响应,然后返回并关闭套接字。要使用保持活动,服务器需要确保它读取客户端发送的所有内容(以便为下一个请求腾出空间)并且只要没有错误就循环,在同一连接上读取新请求。

    做到这一点并不容易,但对于一个简单的测试,您可以在 try 块内添加一个循环,只要没有错误就可以继续处理请求。

    浏览器确实支持保持活动,因此可能不需要在客户端执行任何操作。所有现代浏览器都会缓存并重复使用连接。

  • @Gurkanİlleez 您所说的对于 HTTP 0.9 和 1.0 来说是正确的,但是 HTTP 1.1 默认保持连接打开。

  • 由于我们没有您要绘制的数据,因此很难排除故障。使用随机生成的数据重写将使排除绘图故障变得更容易。

    这是我认为您正在尝试做的事情的最低限度的再现。

    import matplotlib.pyplot as plt
    from matplotlib.animation import FuncAnimation
    import numpy as np
    
    fig = plt.figure()
    ax1 = fig.add_subplot(211)
    ax2 = fig.add_subplot(212)
    
    
    def update(frame):
        
        # '10' here is # of points to start w/;
        # frame increments by 1 every loop - plotting more data.
        x_data = np.arange(10+frame)
        
        # sets fixed seed, generates random 'pressure' data
        np.random.seed(0)
        p_data = np.random.rand(10+frame)
        
        # sets fixed seed, generates random 'temp' data.
        np.random.seed(1)
        tc_data = np.random.rand(10+frame)
        
        # plots data on two subplots
        ax1.plot(x_data, p_data)
        ax2.plot(x_data, tc_data)
    
    
    anim = FuncAnimation(fig, update)
    plt.show()
    

    MatPlotLib 的动画文档(看起来你已经读过了,但对于未来的任何人来说): https://matplotlib.org/stable/users/explain/animations/animations.html

  • 不要再重复这个问题了。这个问题之前已经回答过了,尽管你似乎没有从中学到任何东西。

  • 也许您可以考虑使用 websocket 连接来满足您的需求。每次向服务器端发送请求时,都会打开新连接。我猜您没有使用保持套接字打开的 HTTP 2。您可以检查

  • sima 2月前 0 只看Ta
    引用 12

    我猜 lines[i].StartsWith(taskId) 永远不会返回 true。可能是因为您的 ID 包含在标签中,即 <42> 调试器 应该很容易找到 .

    1. 在 中设置断点 UpdateCompletedTask 。它是否到达?
    2. 看起来 taskId 符合预期吗 lines
    3. 到达 lines[i].Replace("in progress", "completed") 了?

    虽然只要付出足够的努力,你就能让这样的事情顺利进行,但你的代码中还是存在很多问题。尤其是你 对字符串的依赖 ,这很容易隐藏一些问题,如果使用了正确的类型,编译器就可以发现这些问题。

    正如其他人提到的,有更好的方法来做事:

    网络通信

    使用网络流进行通信比较 困难 ,请参阅 Stephen clearys 的 TCP FAQ 了解所有需要做的事情。尤其是有关消息框架的部分。

    但幸运的是,您不需要自己做这件事。有各种各样的高级协议和使用这些协议的库。而且这些协议往往更容易使用,因为您可以发送 消息 对象 ,而不仅仅是字节流。基于请求-响应的协议(如 http 或 gRPC)听起来最适合您的用例。

    贮存

    虽然纯文本/csv 文件有时可以用作 erzats 数据库,但从长远来看,使用真正的数据库可能会节省您的时间和精力。

    有免费的全功能数据库,如 postgres,或流程稍微简单的数据库,如 SQLite 。无论哪种情况,通常使用对象关系映射器 (ORM) 来为您在数据库行和对象之间进行转换。 实体框架 (EF) 可能是最受欢迎的选择。

    我个人会将其作为 ASP.Net webapi 项目 (即 http)来执行,并通过 EF 访问 SQLite 后端。应该有大量关于如何进行设置的教程和其他资源。

  • nKc 2月前 0 只看Ta
    引用 13

    - 呃。为什么!?就像你对自己说“我怎样才能让这项工作尽可能地困难?我知道,我会自己动手做所有事情;数据库、通信、RPC……也许几十年后,如果我有时间,我会编写自己的操作系统来运行这一切”

  • 说实话,上面的代码有很多错误,很难知道从哪里开始。我能看到的问题:使用文件而不是正确的数据库。在

返回
作者最近主题: