NetStreams NetStreams Overview

NetStreams overview

This library is designed as an extension of the newObjects ActiveX Pack1 (Pack1) library. In the hierarchy started with Pack1 it is the core and libraries like this one (NetStreams) are options that can be installed with it. These optional libraries benefit of certain features of Pack1 - they need them in order to provide their full functionality. In NetStreams this is mostly about the SFStream object which does the actual data transfer. Thus the objects in the NetStreams library are intended to establish a connection, once done a SFStream object is attached to it and the data operations are made in a file-like manner.

So, the NetStreams library implements standard IStream interfaces for sockets and allows the transfer operations to be carried over them. This allows virtually any software or a component that "understands" the "IStream language" to work with them. This is a de-facto standard for stream-like objects introduced by Microsoft long and thus allows different applications, written in different languages to work with file-like object in virtually the same way. The newObjects ActiveX Pack1 provides its SFStream object mostly for the scripting languages to allow them access the IStream standard features without need to write code in C++ or VB for example. You may have noticed that there is an object called SFFileStream in that library - it implements this standard interface for regular file system files (the feature is not available from Microsoft, so it fills the gap). The real work with files is done by attaching a SFStream object to a SFFileStream object opened over a certain file (SFMain and SFStorage objects do this automatically for you and it remains transparent in many cases). Very similar is the case with NetStreams. In it you have the SocketStream object which implements the IStream for sockets and thus it is used through SFStream too. 

The differences are in the initial phase - file opening or network connection creation. Where SFFileStream has file open/create facilities, SocketStream has methods and properties that allow you establish a connection and learn/set details about it. Lets illustrate it with a few lines of code:

Set nsMain = Host.CreateObject("newObjects.net.NSMain")
Set addr = nsMain.GetHost("myserver.com")
addr.Port = CLng(myPort)
Set socket = nsMain.NewSocket
b = socket.Socket
If Not b Then
  ' Error handling - socket.LastError holds the error text
End If
b = socket.Connect(addr)
If Not b Then
  ' Error handling - socket.LastError holds the error text
End If
Set strm = Host.CreateObject("newObjects.utilctls.SFStream")
strm.SetStream socket
Response.Write strm.ReadText(200)

In this piece of code the NSMain is used as helper for the other objects creation (it simplifies their construction and allows some other operations to be performed). We request a name lookup by using the GetHost method and we set a TCP port (TCP is default protocol and that is why there is no code to set this) to the SocketAddress object returned. Suppose on the other side we have a server that outputs some data to the connecting party so the rest is to establish a connection and read something. The Socket method initializes the created SocketStream object and Connect tries to connect to the address we prepared above. If everything is ok we reach a connected state where we can create a SFStream object and bind it to our socket. Then everything we need to do is read or write using appropriate methods of SFStream (can be ReadText/WriteTxt for textual communication or ReadBin/WriteBin if binary data is to be transferred).

This is a sample about a client connection, if we want to create a server the steps are different but after the initial phase we still use the same SFStream object for the actual data transfer.

newObjects Copyright 2001-2006 newObjects [ ]