GUI for script

Do you want to use sockets on the JScript (VBScript) program?

  1. You can't use "Windows Sockets" for standard Windows Script Host shell (wscript.exe)!
  2. I can use "Windows Sockets" for advanced Windows Script Host shell (engine.exe)!
Here's an example that writes the server on the port 9000 (Port must be open: ~XP see {win}\system32\drivers\etc\services file):
' Const section
AF_INET     =   2               ' internetwork: UDP, TCP, etc.

SOCK_DGRAM  = 0
SOCK_STREAM = 1

'The code VBScript

Dim flag(6), my_host, sock_id, i, text 
    my_host = TCPIP.gethostname()
    sock_id = 100

flag(0) = TCPIP.WSAStartup(2,0)
flag(1) = TCPIP.socket(sock_id, AF_INET, SOCK_STREAM, 0)
flag(2) = TCPIP.fill_addr(sock_id, my_host, "9000")
flag(3) = TCPIP.bind(sock_id)
flag(4) = TCPIP.listen(sock_id, 1024)
flag(5) = TCPIP.acceptThread(sock_id)

For i = 0 To 5
    Window.TextOut 1, 50, 30 + 20*i, i & ": " & flag(i)
Next

'The callback function (event)
Function EventByteRecv(id, rbyte)
         If id = sock_id Then
            text = text &  String(1, rbyte)
         End If
End Function

Function EventEndAcceptThread(id)
   Window.Delete(2)
   Window.TextOut 2, 70, 150, "Recv: " & text
   Window.UpdateWindow()
   TCPIP.acceptThread(sock_id)
   text = ""
End Function

   AF_INET     =   2               /* internetwork: UDP, TCP, etc. */
   SOCK_STREAM = 1

// The code JScript
var flag = new Array();
var my_host = TCPIP.gethostname();
var sock_id = 100;

flag.push(TCPIP.WSAStartup(2,0)); //major=2, minor=0
flag.push(TCPIP.socket(sock_id, AF_INET, SOCK_STREAM, 0));
flag.push(TCPIP.fill_addr(sock_id, my_host, "9000"));
flag.push(TCPIP.bind(sock_id));
flag.push(TCPIP.listen(sock_id, 1024));
flag.push(TCPIP.acceptThread(sock_id));

for (var i=0; i<flag.length; i++)
      Window.TextOut(1, 50, 30 + 20*i, i + ": " + flag[i]);

var text = "";
function EventByteRecv(id, byte)
{ text = text +  String.fromCharCode(byte);
};

function EventEndAcceptThread(id)
{  Window.Delete(2);
   Window.TextOut(2, 70, 150, "Recv: " + text);
   Window.UpdateWindow();
   TCPIP.acceptThread(sock_id); // new accept
   text = "";
};
more