Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bulletproofing a VBScript TelNet client agains all comms errors.

Status
Not open for further replies.

Harmonitron

Programmer
Nov 9, 2005
3
US
I have an industrial weigh scales that makes each weight reading available on a TCP/IP server (or UDP server - I'm not sure of the correct terminology). The following script listens for the data and, in the full version, stores each reading in the database. The script works well until the scales is powered down or there is a break in the network connection, etc.

First, how do I detect if the connection is lost?
Second, what's the best way to restore?

Many thanks,
Code:
'======================================================================
'Language:		VBScript can run on Windows WHS
'Use:			cscript scriptname.vbs
'======================================================================
'Requires:		w3sockets.dll
'Download:		[URL unfurl="true"]http://tech.dimac.net/default3.asp?M=FreeDownloads/Menu.asp&P=FreeDownloads/FreeDownloadsstart.asp[/URL]
'Documentation:	[URL unfurl="true"]http://www.dimac.net/Products/FreeProducts/w3Sockets/Reference/Refstart.htm[/URL]
'Description ==========================================================
'Opens a TelNet connection to listen to a TCP/IP server.
'Data received is displayed one line at a time.
'======================================================================

telnethost = "192.168.1.5:9000"

	'Create the telnet connection.
	Dim oSocket, iErr, sSocketText
	sSocketText = ""
	Set oSocket = CreateObject("Socket.TCP")
	oSocket.DoTelnetEmulation = True
	oSocket.TelnetEmulation = "TTY"
	oSocket.Host = telnethost
	oSocket.Open

	'Main loop
	Do
		On Error Resume Next
		sSocketText = Trim(oSocket.GetLine)
		If Err.Number <> 0 Then
			'GetLine times out with error 0x8000FFFF after a minute with no comms.
			WScript.Echo Time() & "... waiting for data from server."
		End If
		If sSocketText > "" Then 
			WScript.Echo sSocketText
		End If
	Loop 
	oSocket.Close	'Script never reaches this line.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top