//********************************************************
// Project: ASocks Library v3.5 - Telnet Demo - GUI Ver.
//********************************************************
// Author: Michael Mc Vicker
// Copyright: © 03/21/03 - All Rights Reserved
// FileName: TELNETGUI.PRG
//********************************************************
//
// aSocks Sample Application:
// Sample application to demonstrate the functionallity
// of the aSocks TCP/IP Library.
//
// Components:
//
//
// Updates:
// Last Update: 03/21/03 by MMM
//
// Notes:
//
//********************************************************
#include "Gra.ch"
#include "Xbp.ch"
#include "Common.ch"
#include "Appevent.ch"
#include "Font.ch"
// License Key Includes
#Include "CSKeys.ch"
#Include "ASocksKey.ch"
#Include "aSocksConst.ch"
// Set up default Server & Port
#Define DEFAULT_SERVER ""
#Define DEFAULT_PORT ""
//*******************************
Procedure AppSys ( )
// Stop Console Window
Return
//*******************************
PROCEDURE Main
LOCAL nEvent, oXbp, mp1, mp2
Local oTel := aprTelnet():New(ASOCKS_LICENSE_KEY,CSTOOLS_LICENSE_KEY)
dlgTelnet():New(oTel):Create(oTel)
nEvent := xbe_None
WHILE nEvent != xbeP_Close
nEvent := AppEvent ( @mp1, @mp2, @oXbp )
oXbp:HandleEvent ( nEvent, mp1, mp2 )
IF nEvent == xbeP_Quit
oTel:Destroy()
QUIT // AppQuit()
ENDIF
ENDDO
RETURN
// *********************************
CLASS dlgTelnet FROM _dlgTelnet
EXPORTED:
METHOD init
METHOD create
ENDCLASS
// *********************************
METHOD dlgTelnet:init( oTel, oParent, oOwner, aPos, aSize, aPP, lVisible )
* Execute method of the super class
::_dlgTelnet:init( oParent, oOwner, aPos, aSize, aPP, lVisible )
::btnConnect:activate := {|| iif(oTel:Connect(::Server:GetData(),Val(::Port:GetData())) > 0, ShowStat( Self,GRA_CLR_BLACK, GRA_CLR_GREEN, "Connected"), ShowStat( Self,GRA_CLR_WHITE, GRA_CLR_RED, "Disconnected") )}
::btnDisconnect:activate := {|| iif(oTel:Disconnect(), ShowStat(Self,GRA_CLR_WHITE,GRA_CLR_RED,"Disconnected"),ShowStat(Self,GRA_CLR_BLACK,GRA_CLR_YELLOW,"Unknown Status")) }
::btnSend:activate := {|| ::Transaction:SetData(::Transaction:GetData()+CR_LF+"Local > "+Trim(::Command:GetData())), ShowStat(Self,-1), oTel:Write(Trim(::Command:GetData())+CR_LF), cText := oTel:Read(),ShowStat(Self,-2) ,ShowData(Self, ::Transaction:GetData()+CR_LF+"Remote > "+cText) }
::keyBoard := {| nKeyCode, uNIL, Obj | iif(nKeyCode = xbeK_RETURN, EVAL(::btnSend:Activate),)}
::btnRead:activate := {|| ShowStat(Self,-1), ShowData(Self, ::Transaction:GetData()+CR_LF+"Forced Read > "+Trim(oTel:Read())),ShowStat(Self,-2)}
::btnIsThere:activate := {|| ShowStat(Self,-1), ShowData(Self, ::Transaction:GetData()+CR_LF+"Is There() > "+Trim(Var2Char(oTel:IsThere()))),ShowStat(Self,-2)}
::btnBreak:activate := {|| ShowStat(Self,-1), ShowData(Self, ::Transaction:GetData()+CR_LF+"Break() > "+Trim(Var2Char(oTel:Break()))),ShowStat(Self,-2)}
::btnClear:activate := {|| ::Transaction:SetData("Ready") }
// for use if included in seperate application
//::btnExit:activate := {|| ::Destroy() }
// for use if included in stand-alone application
::btnExit:activate := {|| PostAppEvent( xbeP_Close ) }
RETURN self
// *********************************
METHOD dlgTelnet:create( oTel, oParent, oOwner, aPos, aSize, aPP, lVisible )
* Execute method of the super class
::_dlgTelnet:create( oParent, oOwner, aPos, aSize, aPP, lVisible )
::Server:SetData(DEFAULT_SERVER)
::Port:SetData(DEFAULT_PORT)
::Transaction:SetData("Ready."+CR_LF )
SetAppFocus(::btnConnect)
* Display the form
::show()
RETURN self
//*******************************
Function ShowStat ( oDlg, nFG, nBG, cText )
//*******************************
If nFG = -1
nFG := GRA_CLR_BLACK
nBG := GRA_CLR_YELLOW
cText := "Working..."
EndIF
If nFG = -2
nFG := GRA_CLR_BLACK
nBG := GRA_CLR_GREEN
cText := "Ready"
EndIF
If ValType(nFG) = "N"
oDlg:stStatus:SetColorFG(nFG)
EndIF
If ValType(nBG) = "N"
oDlg:stStatus:SetColorBG(nBG)
EndIF
If ValType(cText) = "C"
oDlg:stStatus:SetCaption(cText)
EndIF
Return (.T.)
//*******************************
Function ShowData ( oDlg, cText )
//*******************************
Local nFirstChar := 0, nLines := 0
If ValType(cText) != "C"
cText := Var2Char(cText)
EndIF
nLines := Max(MLCount(cText),1)
nFirstChar := MlPos( cText,255,iif(nLines > 25, nLines-24,1))
oDlg:Transaction:SetData(cText)
oDlg:Transaction:setFirstChar( nFirstChar )
Return (.T.)
// *********************************
#include "GUI\_TELNETGUI.PRG"
|