Release Notes August 1, 1999
Written by Hippo2000
BASP21.DLL Socket Object is
a component supporting TCP/IP communication from VBScript in ASP,
Visual Basic, Excel VBA and WSH(Windows Scripting Host) etc.
*Connect(dest,port[,timeout]) :Establishes a
connection
*Read(data[,mode]) : Receives data
*ReadLine(data) : Receives data by lines.
*Write(data) : Sends data.
*WriteHex(data) : Sends data expressed in
Hexadecimal.
*Close() : Closes the connection.
Create object names "basp21.socket" by CreateObject Method.
Set bsocket = Server.CreateObject("basp21.socket") ' ASP Set bsocket = CreateObject("basp21.socket") ' VBA or VB Set bsocket = WScript.CreateObject("basp21.socket") ' WSH
Call method of Object you just created.
variable = bsocket.method_name(parameter)
Establishes a connection to the host in TCP/IP supporting socket stream.
rc = bsocket.Connect(dest,port[,timeout]) dest [in] : IP address or network hostname to connect port [in] : Port number timeout [in] : Communication Timeout in seconds. (default:120) rc [out] : Result code in number 0 : Connection OK! >0 : Winsock Error Typical error is : 11001 Hostname not found -1 : Socket open error -2 : Timeout ex: rc = bsocket.Connect("www.hi-ho.ne.jp",80)
Receives data from the connected host. You can specify the format of receiving data as binary, hexadecimal and so on.
rc = bsocket.Read(data[,mode]) data [in] : Variable for receiving data. In Visual Basic, use 'Variant' type variale. mode [in] : Format of receiving data, like below: 0 : String (Default) 1 : Binary. Data will be returned in byte array. 2 : String expressed in hexadecimal. 16 : String. Arrived data will be peeked. Data is left in buffer. 17 : Peek in binary. 18 : Peek in hexadecimal-format. rc [out] : Result code in number. 0 : Receiving OK. > 0: Winsock Error -1 : Socket close. -2 : Timeout. -3 : No data. Ex. rc = bsocket.Read(data)
Receives data from the connected host by lines.
rc = bsocket.ReadLine(data) data [in] : Variable for receiving data. In Visual Basic, use 'Variant' type variale. Newline is removed. rc [out] : Result code in number. 0 : Receiving OK. > 0 : Winsock Error -1 : Socket close. -2 : Timeout -3 : No data Ex. rc = bsocket.ReadLine(data)
Sends data to the connected host.
rc = bsocket.Write(data) data [in] : Variable for sending data. In Visual Basic, use 'Variant' type variable. If you want to send binary data, use byte array. rc [out] : Result code in number. 0 : Sending OK > 0: Winsock Error -1 : Socket close. -2 : Timeout -3 : No Data Ex. rc = bsocket.Write(data)
Sends data to the connected host, translating the data from hexadecimal-format to binary.
rc = bsocket.WriteHex(data) data [in] : Variable for sending data. In Visual Basic, use 'String' type variable. rc [out] : Redult code in number. 0 : Sending OK. > 0: Winsock Error -1 : Socket close. -2 : Timeout. -3 : No data. Ex. rc = bsocket.WriteHex("0001FFFF")
Disconnects the connection.
Ex. bsocket.Close
Following examples show the example to get image from a HTTP-server, and save it in a specified file.
Dim bobj As Object, rc1 As Long, datax As Variant Dim bsocket As Object, datas As Variant Dim mode As Integer, lenx As Integer Set bobj = CreateObject("basp21") Set bsocket = CreateObject("basp21.socket") rc1 = bsocket.Connect("www.hi-ho.ne.jp", 80, 10) bsocket.write ("GET /babaq/images/basp21a.gif HTTP/1.0" & vbCrLf & vbCrLf) rc1 = bsocket.readline(datas) While rc1 = 0 And Len(datas) > 0 ' Skip Header lines rc1 = bsocket.readline(datas) Wend rc1 = bsocket.read(datax, 1) ' Read image in binary. mode = 0: lenx = 0 While rc1 = 0 lenx = lenx + UBound(datax) + 1 rc1 = bobj.BinaryWrite(datax, "d:\basp21.gif", mode) mode = mode + 1 rc1 = bsocket.read(datax, 1) Wend
Set bobj = WScript.CreateObject("basp21") Set bsocket = WScript.CreateObject("basp21.socket") Set WshShell = Wscript.CreateObject("Wscript.Shell") WshShell.Run ("notepad") rc1 = bsocket.Connect("www.hi-ho.ne.jp", 80, 10) if rc1 <> 0 then bobj.debug "connect error " & rc1 WScript.quit end if rc1 = bsocket.write ("GET /babaq/images/basp21a.gif HTTP/1.0" & vbCrLf & vbCrLf) if rc1 <> 0 then bobj.debug "write error " & rc1 WScript.quit end if bsocket.readline datas bobj.debug datas While rc1 = 0 And Len(datas) > 0 ' Skip Header lines rc1 = bsocket.readline(datas) bobj.debug datas Wend rc1 = bsocket.read(datax, 1) ' Read image in binary mode = 0: lenx = 0 While rc1 = 0 lenx = lenx + UBound(datax) + 1 rc1 = bobj.BinaryWrite(datax, "d:\basp21.gif", mode) mode = mode + 1 rc1 = bsocket.read(datax, 1) Wend bobj.debug lenx
Copyright 1999 Tatsuo Baba,All
rights reserved.