Using MSWinsock.Winsock's GetData method from JScript? 
Author Message
 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();


Thu, 14 Nov 2002 03:00:00 GMT  
 Using MSWinsock.Winsock's GetData method from JScript?
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();


Fri, 15 Nov 2002 03:00:00 GMT  
 Using MSWinsock.Winsock's GetData method from JScript?
I was afraid someone was going to say that.

Can you think of any work-arounds? Does it sound feasible to say write the
socket code as a VBScript component which itself is called from some JScript
running under cscript.exe?

Thanks,
- Lee


You don't...  JScript doesn't support ByRef arguments.

--
Michael Harris
MVP Scripting



Fri, 15 Nov 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. GetData using MSWinsock.Winsock

2. winsock.GetData problem

3. Get HTML pages with mswinsock.winsock

4. Creating an instance of MSWinsock.Winsock gives error 0x80040112

5. ActiveX Object - MSWinsock.Winsock

6. VB call to JScript method returns method's source

7. JScript's UTC method equivalent in VBScript

8. Can't Launch Office 2000 shortcuts using RUN method in Win2k

9. Using Excel's GetSaveAsFilename Method

10. using MSWINSOCK.OCX with Scripts

11. Jscript and Method error using ADSI

12. using methods with JScript objects stored in session object

 

 
Powered by phpBB® Forum Software