【问题标题】:Help with sending text thou TCP/IP or LAN帮助在 TCP/IP 或 LAN 上发送文本
【发布时间】:2010-10-23 20:41:35
【问题描述】:

大家好,我正在尝试从虚拟机 (VMWARE) 向我的本地计算机发送文本消息,以便我可以点击 VM 中的按钮并让它在本地执行某些操作。

是否可以使用 VB6 或 VB.net 通过 IP、TCP/IP、LAN 发送文本?我正在查看 net send 来发送一些东西,但它似乎对我不起作用(而且它似乎为您发送的每个文本弹出一个对话框)。我已经试过了:

http://www.codeproject.com/KB/vb/CfSimpleSendComp.aspx

但它似乎在我的计算机上根本不起作用?我已经尝试了机器的 IP 和计算机的名称。也许是 VB 中的 .NET Remoting

谁能告诉我是否有其他方法可以做我想做的事?

谢谢!

大卫

【问题讨论】:

    标签: vb.net visual-studio-2008 vb6 communication tcp


    【解决方案1】:

    您也可以考虑使用 Eneter Messaging Framework。
    它重量轻,非常易于使用。

    对不起,我不熟悉VB语法,但在C#中整个实现 在这里:(您可以将代码复制粘贴到您的项目中,包括 Eneter.Messaging.Framework.dll 并将 IP 更改为您的。)

    服务器监听字符串消息。

    using System;
    using Eneter.Messaging.EndPoints.StringMessages;
    using Eneter.Messaging.MessagingSystems.MessagingSystemBase;
    using Eneter.Messaging.MessagingSystems.TcpMessagingSystem;
    
    namespace StringReceiver
    {
        class Program
        {
            static void Main(string[] args)
            {
                // Create Tcp based messaging.
                IMessagingSystemFactory aTcpMessaging = new TcpMessagingSystemFactory();
                IInputChannel anInputChannel = aTcpMessaging.CreateInputChannel("127.0.0.1:7091");
    
                // Create string message receiver
                // Note: it is possible to receiver typed messages too.
                IStringMessagesFactory aStringMessagesFactory = new StringMessagesFactory();
                IStringMessageReceiver aStringMessageReceiver = aStringMessagesFactory.CreateStringMessageReceiver();
                aStringMessageReceiver.MessageReceived += StringMessageReceived;
    
                // Attach the input channel to the string message receiver
                // and start listening.
                Console.WriteLine("String sercer is listening.");
                aStringMessageReceiver.AttachInputChannel(anInputChannel);
            }
    
            // Processing messages.
            static void StringMessageReceived(object sender, StringMessageEventArgs e)
            {
                Console.WriteLine("Received message: " + e.Message);
            }
        }
    }
    

    发送字符串消息的客户端:

    using Eneter.Messaging.EndPoints.StringMessages;
    using Eneter.Messaging.MessagingSystems.MessagingSystemBase;
    using Eneter.Messaging.MessagingSystems.TcpMessagingSystem;
    
    namespace StringMessageSender
    {
        class Program
        {
            static void Main(string[] args)
            {
                // Create Tcp based messaging.
                IMessagingSystemFactory aTcpMessaging = new TcpMessagingSystemFactory();
                IOutputChannel anOutputChannel = aTcpMessaging.CreateOutputChannel("127.0.0.1:7091");
    
                // Create string message receiver
                // Note: it is possible to receiver typed messages too.
                IStringMessagesFactory aStringMessagesFactory = new StringMessagesFactory();
                IStringMessageSender aStringMessageSender = aStringMessagesFactory.CreateStringMessageSender();
    
                // Attach the output channel to the string message sender
                // so that we can send messages via Tcp to desired Ip address.
                aStringMessageSender.AttachOutputChannel(anOutputChannel);
    
                // Send message.
                aStringMessageSender.SendMessage("Hello world.");
           }
       }
    

    }

    Eneter Messaging Framework 可以在www.eneter.net下载。

    如果您想获得更多技术信息:www.eneter.net/OnlineHelp/EneterMessagingFramework/Index.html 更多示例:eneter.blogspot.com

    【讨论】:

    • 感谢 Ondrej 抽出宝贵时间写下所有内容。但是,我只是使用了一些 VB.net 代码。
    【解决方案2】:

    您需要一个客户端和一个服务器,两端各有一个。它们可以通过 TCPIP(TCP 或 UDP)、Microsoft Networking(命名为 Pipes、Mailslots)或您拥有的任何东西进行通信。一些选项取决于两台机器运行的操作系统,但既然你提到了 NET SEND,我们可能可以假设一些 Windows 风格。

    在更高版本的 Windows NT(Vista、Windows 7)中不再提供 Messenger 服务,因此它不是最佳选择。还有其他 Mailslots 信使以及大量 UDP 信使。

    真正的问题是您想要“按下按钮”执行什么操作。哎呀,如果 Telnet 能满足您的需求,您就可以轻松运行 Telnet。

    不要忘记,您可能必须打开防火墙才能使其中任何一个工作。

    .Net Remoting 在 VB 中不可用,您必须指的是 VB.Net。这是一种远程对象调用技术,可能不是您想要的。

    选择一个开发工具集并使用它为 TCP 或 UDP 套接字提供的任何东西,您可能会更快地获得结果。

    【讨论】:

      【解决方案3】:

      有几种方法。最好的方法取决于您如何定义“短信”。

      如果你真的只需要点击一个按钮并在远程机器上运行一个命令,我会在 Process 对象中运行PsExec。俗气但有效。比如:

      Using p as new Process()
          p.StartInfo.FileName = "c:\path\to\PsExec.exe"
          p.StartInfo.Arguments = "\\RemoteComputerName RemoteCommand.exe"
          p.Start()
      End Using
      

      如果您需要使用自定义协议进行双向通信,我会使用WCFTCPListener and TCPClient 类来创建您自己的套接字服务器和客户端。

      我会远离远程处理。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-02-17
        • 2012-10-19
        • 1970-01-01
        • 2012-12-17
        • 2018-09-19
        • 1970-01-01
        相关资源
        最近更新 更多