Logo
English Russian German French Spanish Italian
contact usprivacy
   Support Forums
chart
• About the product
• Download
• Sample projects:
Using with Visual Basic
Using with VB.NET
Using with C#
Using with ASP
Using with ASP.NET
Using with Office (VBA)
Using with VBScript
Using with JavaScript
Using with SQL Server
• Support Forum
OISV - Organization of Independent Software Vendors - Contributing Member
Winsock Component - Using with JavaScript

JavaScript sample, based on OstroSoft Winsock component (oswinsck.dll)
Download sample script

Minimum requirements: oswinsck.dll*
* If you don't have OstroSoft Winsock Component, see installation instructions

1. Create file with extension ".js" and open it with
text editor of your choice (Notepad is fine)
2. Enter the following code:

var oWinsock;
var sURL = '';
var sPage = '';
var sServer = '';
var nPort = 80;
var sSource = '';
var bClose = false; 

//enter desired URL below
sURL = 'http://localhost';

//parse URL
if (sURL.indexOf('://') > 0)
  sServer = sURL.substr(sURL.indexOf('://') + 3);

if (sServer.indexOf('/') > 0) {
  sPage = sServer.substr(sServer.indexOf('/') + 1);
  sServer = sServer.substring(0, sServer.indexOf('/'));
}

if (sServer.indexOf(':') > 0) {
  nPort = sServer.substr(sServer.indexOf(':') + 1);
  sServer = sServer.substring(0, sServer.indexOf(':'));
}

if (sServer != '') { //connect to the server
  oWinsock = new ActiveXObject("OSWINSCK.Winsock");
  WScript.ConnectObject(oWinsock, "oWinsock_");

  oWinsock.Connect(sServer, nPort);
} else {
  WScript.Echo("Invalid URL");
  bClose = true;
}

function oWinsock_OnConnect() {
  oWinsock.SendData('GET /' + sPage + ' HTTP/1.0\r\n\r\n');
}

function oWinsock_OnDataArrival(bytesTotal) {
  var sBuffer = oWinsock.GetDataBuffer();
  sSource = sSource + sBuffer;
}

function oWinsock_OnError(Number, Description, Scode, Source, 
    HelpFile, HelpContext, CancelDisplay) {
  WScript.Echo(Number + ': ' + Description);
}

function oWinsock_OnClose() {
  oWinsock.CloseWinsock();
  WScript.Echo(sSource);

  oWinsock = null;
  bClose = true;
}

while (!bClose) {
  WScript.Sleep(1);
}

Copyright © 1996-2010 OstroSoft. All rights reserved. info@ostrosoft.com