VBScript/JScript 网络:连接 UDP 或 TCP [英] VBScript/JScript Networking: Connect either UDP or TCP

查看:46
本文介绍了VBScript/JScript 网络:连接 UDP 或 TCP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用独立的 VBScript 或 JScript 文件连接到本地主机上的端口,UDP 或 TCP(最好是 UDP)?我需要向本地主机上的某个端口发送命令.该命令很小,不会有任何本地主机丢失数据包(即使有,也不会那么糟糕),这就是为什么UDP可以很好地工作,只需发送一个数据包即可.

How can I use a stand-alone VBScript or JScript file to connect to a port on localhost, either UDP or TCP (preferable UDP)? I need to send a command to a certain port on localhost. The command is small and there will not be any packet loss to localhost (even if there was, it would not be that bad), that is why UDP would work great, just send a packet.

但目前我很难找到有关 VBScript 或 JScript 网络的任何示例.

But at the moment I am having a hard time finding any examples on VBScript or JScript networking.

在 Windows XP 之前,我不关心任何事情.

I don't care about anything before Windows XP.

推荐答案

VBScript 和 JScript 本身没有直接使用 Sockets 的能力.这些语言允许您与能够使用套接字的 ActiveX/COM 对象进行交互.

VBScript and JScript do not natively have the ability to directly use Sockets. What these languages do allow you to do is to interact with ActiveX/COM objects that have the ability to use Sockets.

例如,您可以使用 MSXML2.XMLHTTP 与 HTTP/HTTPS 服务器通信.

For example, you can use MSXML2.XMLHTTP to talk to an HTTP/HTTPS server.

Dim objHTTP
Set objHTTP = CreateObject("MSXML2.XMLHTTP")
objHTTP.open "GET", "http://www.google.com", false
objHTTP.send 
WScript.Echo objHTTP.responseText

现在,真正的问题.Windows 是否有用于与原始套接字交互的 ActiveX/COM 对象?此处的简短回答是否定的,但您确实有其他选择.

Now, the real question. Does Windows have an ActiveX/COM object for interacting with raw Sockets? The short answer here is No, but you do have alternatives.

  • 有一个名为 mswinsck.ocx 的Winsock ActiveX"库随附非常旧版本的 Visual Studio(版本 6 及更早版本).虽然,让这个库工作会有点棘手,因为它本来是要从 Visual基本而不是 VBScript.

  • There is a "Winsock ActiveX" library named mswinsck.ocx that comes with very old versions of Visual Studio (version 6 and earlier). Although, getting this library to work will be kind of tricky as it was meant to be used from Visual Basic and not VBScript.

您可以从第三方购买一个

您可以写入 你自己的.不过,这可能比它的价值更麻烦.您将远远超出 VBScript,因此放弃 VBScript 并为此编写合适的程序会更简单.

You can write your own. This may be more trouble than it is worth, though. You'll be stepping so far outside of VBScript that it would be simpler to give up on VBScript and write a proper program for doing this.

您可以切换到更详细的语言,例如 ActiveState PerlPython.两者都对套接字提供本机支持,但同样,这可能超出您的舒适范围.

You can switch to a more verbose language such as ActiveState Perl or Python. Both have native support for sockets, but again, this might be outside of your comfort zone.

这篇关于VBScript/JScript 网络:连接 UDP 或 TCP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆