远程将消息传递到 C# 控制台应用程序
我需要能够发送字符串消息并从我们组织内运行的控制台应用程序接收字符串响应。我想从远程 IP 地址来回传递简单的字符串。最好的方法是什么?我的第一个想法是在套接字上监听,但这似乎有点矫枉过正。我已经考虑过成为 WMI 生产者/消费者,但这也相当复杂。还有 System.Runtime.Remoting.Channels.Tcp 来注册消息。
似乎这些方法中的任何一个都可以工作,但是当字符串到达时触发事件的最简单方法是什么以及如何从 ac# 控制台应用程序传回字符串?
I need to be able to send a string message and receive a string response from a console app running within our organization. I want to pass simple strings back and forth from a remote IP address. What's the best way to do this? My first thought is to listen on a socket, but that seems like overkill. I've looked a little into becoming a WMI producer/consumer, but that's pretty involved too. Also there's System.Runtime.Remoting.Channels.Tcp to register for messages.
It seems like any of these methods would work, but what's the easiest way to get an event to fire when a string arrives and how to pass a string back from a c# console app?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议您创建一个 WCF 服务,因为它看起来比您的替代方案更简单。
I suggest you to create a WCF service, as it seems simpler than your alternatives.
如果您需要在控制台应用程序中使用此功能,我个人认为使用套接字实现此功能是最简单的选择,特别是如果“远程 IP 地址”不是用 C# 编写的或不在您的控制之下。
TcpClient 类非常易于使用,如果您所做的只是来回传递一些字符串。
一个潜在的问题是:如果远程 IP 上的“服务器”不是用 C# 编写的,请确保处理传递的字节流中的任何编码问题,因为 C# 使用 Unicode 字符串。
If you need this to be in a console application, I personally think that implementing this using sockets is the easiest option, especially if the "Remote IP Address" isn't written in C# or under your control.
The TcpClient class is quite easy to use, if all you're doing is passing a few strings back and forth.
One potential gotcha: If the "server" on the remote IP isn't written in C#, make sure to take care of any encoding issues in the passed byte stream, since C# uses Unicode strings.