开发者

VBScript/JScript Networking: Connect either UDP or TCP

开发者 https://www.devze.com 2023-03-12 18:10 出处:网络
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 smal

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.

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

I don't care about anything before Windows XP.


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.

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

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.

  • 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.

  • You can purchase one from a 3rd party

  • 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.

  • 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消