I'm trying to use sockets to connect to a server through HTA scripting. Is this possible? There's isn't much information on the web, some examples would be greatly appreciated.
+1
A:
There is no socket access built into JScript, but you can use any of the installed ActiveX components.
I guess there are some 3rd party ones that provide raw socket access, but there are none in vanilla Windows installations. This means you'd not only have to distribute the HTA, but also install an ActiveX component, which would make deployment rather cumbersome.
If you can, use HTTP as a way to access remote resources, and use the built-in XmlHttpRequest or WinHttpRequest objects that comes with Windows.
Tomalak
2010-09-09 12:25:17
Unfortunately I can't use the ActiveX HTTP component to access remote HTTP servers as I get an Access denied because of the `same-origin` policy. Any ideas?
Luca Matteis
2010-09-09 12:28:12
@Luca: I'm pretty sure a WinHttpRequest object can make any request you want.
Tomalak
2010-09-09 12:38:09
@Tomalak: That's what I thought as well. However I get this error when using the WinHTTPRequest component. `The connection with the server was terminated abnormally`. Here's the piece of code I'm running: http://codepad.org/gKIxwJEi
Luca Matteis
2010-09-09 12:42:37
@Luca: Maybe the proxy settings are missing? To find out what's really going on, it's easiest to use a network sniffer and analyze the traffic. Should be pretty easy to pin this problem.
Tomalak
2010-09-09 12:44:49
@Tomalak, tried using Wireshark, no HTTP packets are initiated when I run that code. So far I'm at a lost case... there's like no documentation for this on the web. Any help would be greatly appreciated.
Luca Matteis
2010-09-09 13:27:20
@Luca: Try looking for TCP packets. The "connection terminated abnormally" message indicates there *must be* some network traffic going on. My bet is still on the missing proxy settings. IIRC, the WinHttpRequest object does not care for your Internet Explorer settings and must be configured separately through code.
Tomalak
2010-09-09 13:44:19
@Tomalak: this might be it, however I can't find information on the API to use for proxy configuration. And my browsers don't have any weird Proxy configuration... just default stuff.
Luca Matteis
2010-09-09 13:56:27
@Luca: Does "default stuff" mean there is no proxy? PS: Why did you accept the answer?
Tomalak
2010-09-09 14:34:14
@Tomalak, because you've answered my question about the Sockets... this extra HTTP talk is extra I guess... but anyway yeah by "default stuff" I mean that there's no proxy :)
Luca Matteis
2010-09-10 08:17:43
@Luca: For the record: I've tried WinHttpRequest and it works perfectly for me.
Tomalak
2010-09-10 11:37:42