我正在尝试制作一个程序来通过服务器/客户端方法控制计算机的基本功能。我只需要将字符串从服务器发送到客户端,反之亦然。我发现的每个示例都非常陈旧,不再有效,或者解释不清,或者在 C# 中。
我几乎有一个工作示例,但是我遇到了一个线程问题,在我打开从服务器到客户端或客户端到服务器的连接的线程后,它不允许我修改 UI 中的元素。不知道如何解决这个问题,我没有选择。
本质上,我需要一种在服务器/客户端架构中将文本从一个 IP/端口发送到另一个的方法。
The clue to solving your issue is probably here: "I almost have a working example as is, but I'm running into a threading issue where it won't let me modify elements in the UI after I've opened my thread for the connection from server to client or client to server."
You cannot access controls (UI elements) created on one thread directly from another thread. So if you have another thread and you want to update an element in the UI, you need to use the Control.BeginInvoke Method.
You didn't post any code, so I won't try and give you an example that may be utterly useless in your case, but there's a good article on MSDN here - How to: Make Thread-Safe Calls to Windows Forms Controls. This is for Windows Forms, nut the principals are the same for any application.