I'm a beginner who wanna try to make a simple telnet client app, that connected to TPF mainframe using port 23.
I have coded the app as below:
Code:
Private Const resdip = "172.25.203.194", telnetport = 23
Private Sub cmdConnect_Click()
con.Connect
cmdConnect.Visible = False 'prevent to clicked twice
End Sub
Private Sub con_DataArrival(ByVal bytesTotal As Long)
Dim reply_out As String
textOut.Visible = True
textOut.Text = textOut.Text & reply_out
End Sub
Private Sub con_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
txtlog "Something's went wrong!" & Description & Number & vbclrf
End Sub
Private Sub Form_Load()
If con.State = sckConnected Or con.RemoteHost <> resdip Or con.RemotePort <> telnetport Then
con.Close
End If
con.RemoteHost = resdip
con.RemotePort = telnetport
If con.State <> sckConnected Then
textOut.Visible = False
cmdConnect.Visible = True 'suppress default value
End If
End Sub
After the form's loaded, I got the Connect button (named as cmdConnect) appeared, and it's because the winsock (named as con) state not equal to sckConnected.
After I try to connect it, there is no response I got.
Anyone please help me or give me some advise. Any help is appreciated.
Re: no response after try to connect to remote host
The DataArrival event is triggered when something has been received. You have to read it.
Code:
Private Sub con_DataArrival(ByVal bytesTotal As Long)
Dim reply_out As String
con.GetData reply_out
textOut.Visible = True
textOut.Text = textOut.Text & reply_out
End Sub
Re: no response after try to connect to remote host
Originally Posted by Doogle
The DataArrival event is triggered when something has been received. You have to read it.
Code:
Private Sub con_DataArrival(ByVal bytesTotal As Long)
Dim reply_out As String
con.GetData reply_out
textOut.Visible = True
textOut.Text = textOut.Text & reply_out
End Sub
Thanks Doogle it works now, however I got the data in EBCDIC format and I'm looking for how to translate it to ASCII format.
But thanks for your correction.
Re: no response after try to connect to remote host
Simplest method might be to create a 'look-up' array with 256 elements, each element holding the ASCII equivalent for the EBCDIC value. e.g. Lookup(193) would contain "A" ,where 193 is the EBCDIC value for 'A' = Hex(C1) = 193
Re: no response after try to connect to remote host
BTW I didn't sit and type all that in, I used the following code and attached file to create the module. I've posted it here so you can simply make any changes to the file (eg if you want to translate some of the unprintable characters), run the code and it will create the .bas module for you. (Just change the Paths to the input and output files as necessary)
Code:
Option Explicit
Private Sub Command_Click()
Dim strData As String
Dim strLines() As String
Dim strLine() As String
Dim intFile As Integer
Dim intFileOut As Integer
Dim intI As Integer
Dim intLoc As Integer
intFile = FreeFile()
Open "C:\MyDir\ebcdic.txt" For Input As intFile
intFileOut = FreeFile()
Open "C:\myDir\modEbcdic.bas" For Output As intFileOut
Print #intFileOut, "Option Explicit"
Print #intFileOut,
Print #intFileOut, "Private EBCDICLookup(255) As String"
Print #intFileOut,
Print #intFileOut, "Public Sub SetUpTranslate()"
strData = Input(LOF(intFile), intFile)
Close intFile
strLines = Split(strData, vbNewLine)
For intI = 0 To UBound(strLines)
strLine = Split(strLines(intI), " ")
intLoc = CInt(strLine(0))
If UBound(strLine) > 1 Then
If Len(strLine(2)) = 1 Then
Print #intFileOut, "EBCDICLookup(" & intLoc & ") = " & "Chr(" & (Asc((strLine(2)))) & ")" & vbTab & "'" & strLine(2)
Else
Print #intFileOut, "EBCDICLookup(" & intLoc & ") = Chr(255)" & vbTab & "' Unprintable"
End If
Else
Print #intFileOut, "EBCDICLookup(" & intLoc & ") = Chr(255)" & vbTab & "' Unprintable"
End If
Next intI
Print #intFileOut, "End Sub"
Print #intFileOut,
Print #intFileOut, "Public Function Translate(strEBCDIC As String) As String"
Print #intFileOut, "Dim intI As Integer"
Print #intFileOut, "If Len(strEBCDIC) > 0 Then"
Print #intFileOut, " For intI = 1 To Len(strEBCDIC)"
Print #intFileOut, " Translate = Translate & Chr(EBCDICLookup(Asc(Mid$(strEBCDIC, intI, 1))))"
Print #intFileOut, " Next intI"
Print #intFileOut, "End If"
Print #intFileOut, "End Function"
Close intFileOut
End Sub
Re: no response after try to connect to remote host
Oops, sorry about that ! Must have been a last minute change that I didn't test or something. Glad it's working now though.
To mark the Thread as Resolved go to the top of the Thread and under the 'Thread Tools' menu, click on 'Mark Thread as Resolved', that will close it off.