This script functions similarly to the simple relay sample script, but allows for communications in both directions.
For example connect an incoming telnet connection out to an RS-232 serial connection, and relay data between the two connections.

Imports System.Threading
Module Module1
Dim inHaw, outHAW, inScript, outScript

Sub Main()
inHaw = CreateObject("HAWin32")
outHAW = CreateObject("HAWin32")
Dim datastr

inScript = inHaw.haInitialize("input")
outScript = outHAW.haInitialize("output")

inScript.haSizeHyperACCESS(3)
outScript.haSizeHyperACCESS(3)

inScript.haSetMessageTimer(0)
outScript.haSetMessageTimer(0)

inScript.haOpenSession("simplehost.HAW")
inScript.haConnectSession(4)
While inScript.haGetConnectionStatus = 5
inScript.haWaitForConnection(1, 1000)
If inScript.haGetConnectionStatus = 1 Then
outScript.haOpenSession("com 1.HAW")
outScript.haConnectSession(0)
outScript.haWaitForConnection(1, 10000)
Dim trd2 = New Thread(AddressOf outThread)
trd2.IsBackground = True
trd2.Start()
While (inScript.haGetConnectionStatus = 1 And outScript.haGetConnectionStatus = 1)
datastr = inScript.haGetInput(0, -1, 2500, 1000)
If datastr <> "" Then
outScript.haTypeText(datastr)
End If
End While
outScript.haDisconnectSession()
outScript.haWaitForConnection(2, 1000)
outScript.haCloseSession()

inScript.haDisconnectSession()
inScript.haWaitForConnection(2, 1000)
datastr = ""
inScript.haConnectSession(4)
End If
End While
inScript.haTerminate()
outScript.haTerminate()
End Sub

Private Sub outThread()
Dim datastr
While (inScript.haGetConnectionStatus = 1 And outScript.haGetConnectionStatus = 1)
datastr = outScript.haGetInput(0, -1, 2500, 1000)
If datastr <> "" Then
inScript.haTypeText(datastr)
End If
End While
End Sub

End Module

Return to sample script index