
Using MSWinsock.Winsock's GetData method from JScript?
You don't... JScript doesn't support ByRef arguments.
--
Michael Harris
MVP Scripting
How on earth do you get MSWinsock.Winsock's GetData() working from JScript?
All the VBScript examples I can find use
Dim s As String
GetData s, vbString
which I've translated to
var s = " ";
socket.GetData(s, 8);
but this fails to read any data into the string 's'. I've tried all sorts of
combinations of JScript objects for 's' (including Number and String
objects) and VB data type codes in place of '8', but I just can't get it
working.
I'm using cscript.exe - "Microsoft (R) Windows Script Host Version 5.1 for
Windows" and "Microsoft Winsock Control 6.0" running under NT 4 Workstation
SP6a.
Example source is included below. I'm testing this by telneting to port 6239
and typing 'a'.
Any pointers / help would be much appreciated.
Thanks,
- Lee
var wshShell = WScript.CreateObject("WScript.Shell");
function print(msg)
{
WScript.Echo(msg);
Quote:
}
var listener;
function listen()
{
listener = WScript.CreateObject("MSWinsock.Winsock", "listener_");
listener.localPort = 6239;
listener.bind();
listener.listen();
print("Listening");
Quote:
}
var connections = new Object();
function listener_ConnectionRequest(requestID)
{
print("Connection request " + requestID);
var connection = connections[requestID] =
WScript.CreateObject("MSWinsock.Winsock", "listener_");
connection.accept(requestID);
connection.sendData("Prompt> ");
Quote:
}
function listener_DataArrival(length)
{
print("Accepted " + length + " bytes " + this.socketHandle);
var str = "\0\0\0\0\0";
this.getData(str, 8);
print(":" + str);
Quote:
}
function idle()
{
var ret = 0;
while (ret != 1)
{
ret = wshShell.Popup("Running...", 36000);
}
Quote:
}
function run()
{
print("Init");
listen();
idle();
Quote:
}
run();