/****************************************************************
** **
** Name: DieterConn **
** Author: Dieter Groppé **
** Version: 0.6 **
** Date: 11.04.18 **
** Interpreter: Hollywood 7.1 **
** Licence: Nothing, only Testtool **
** Function: Try some TCP and UDP connections with Hollywood**
** and some gui functions **
** **
** History: **
** **
** 0.1: (19.03.18) **
** - first try to get anything and show it **
** 0.2: (20.03.18-04.04.18) **
** - try a little with TFTP, get my file per tftp only trivial **
** 0.3: (05.04.18-09.04.18) **
** - add a GUI for parameters and outputs **
** 0.4: (11.18-11.04.18) **
** - some finetunig in GUI and program **
** - add blockchecking (for bad tftp-server implementation) **
** 0.6: (17.04.18-17.04.18) **
** - rewrite to get receiveudpmsg **
** **
****************************************************************/
@VERSION 5,0
@APPTITLE "DieterConn"
data$ = "gez.txt\0"
savename$="" .. data$
ipadress$ = "127.0.0.1" /*"192.168.1.111"*/
RRQ = 1
WRQ = 2
ACK = 4
Null$ = "\0"
Ackn$ = Null$ .. ByteChr(ACK)
TFTPMODE$ = "NETASCII\0"
TFTPrequest$ = Null$ .. ByteChr(RRQ) .. data$ .. TFTPMODE$
button$ = {}
blockis = Nil
open = False
@MENU 1, {
{"File", {
{"Get TFTP file...", ID = "get", Hotkey = "G"},
{"Save file...", ID = "save", Hotkey = "S"},
{"Quit", ID = "quit", Hotkey = "Q"}}},
{"?", {
{"About...", ID = "about"}}}
}
@DISPLAY {Menu = 1, Title = "DieterConn", COLOR=$cFcFcF}
Function printstatus()
DebugPrint (temp$)
SetFillStyle(#FILLCOLOR)
Box(10, 450, 600, 20, $CfCfCf)
TextOut (10, 450, temp$)
/*CreateTextObject(1, temp$)
DisplayTextObject(1, 10,250)
FreeTextObject(1)*/
/*Locate (10,250)
Print (temp$)*/
EndFunction
Function NetConn()
a$ = ""
CreateUDPObject(1)
open = True
DebugPrint ( "Ipadress vorher =", ipadress$)
;ipadress$ = ToIP(ipadress$) PRODUZIERT nur FEHLER !
DebugPrint ( "Ipadress nachher =", ipadress$)
SendUDPData(1, TFTPrequest$, ipadress$ , 69)
DebugPrint ( Ackn$ , MidStr(trans$,2,2,#ENCODING_RAW) ,"Ipadress=", ipadress$ ,"port:", portnr)
EndFunction
Function closeconn()
CloseUDPObject(1)
open = False
trans$=""
blockis = Nil
printstatus
EndFunction
Function SaveFile()
OpenFile(1, savename$, #MODE_WRITE )
WriteString(1, a$ , 0, #ENCODING_RAW)
CloseFile(1)
EndFunction
Function MakeGagdet(typ,xc,yc,br,wi,Text$)
ID = MakeButton(Nil, #SIMPLEBUTTON, xc, yc, br, wi, buttonevents)
button$[ID] = LeftStr(Text$ .. " ",4)
Box(xc, yc, br, wi, #BLACK)
Box(xc+1, yc+1, br, wi, #WHITE)
If typ = 2 Then yc = yc - 20
TextOut(xc+2, yc+5, Text$)
EndFunction
Function setfilename()
DebugPrint (savename$)
If StrLen(savename$) <> 0
SetFillStyle(#FILLCOLOR)
Box(12, fny+6, 346, 19, $CfCfCf)
TextOut(12, fny+6, savename$)
EndIf
EndFunction
Function setipadress()
DebugPrint (ipadress$)
If StrLen(ipadress$) <> 0
SetFillStyle(#FILLCOLOR)
Box(12, ipy+5, 346, 19, $CfCfCf)
TextOut(12, ipy+5, ipadress$)
EndIf
EndFunction
Function setdata()
DebugPrint (data$)
If StrLen(data$) <> 0
SetFillStyle(#FILLCOLOR)
Box(12, day+4, 346, 19, $CfCfCf)
TextOut(12, day+4, data$)
EndIf
EndFunction
/*
** Event callback that handles menu selections
*/
Function p_Receive(msg)
If blockis=Nil Then blockis=$0001
trans$, ipadress2$, portnr = ReceiveUDPData(1)
If portnr <> Nil
DebugPrint ( Ackn$ , MidStr(trans$,2,2,#ENCODING_RAW) ,"Ipadress=", ipadress2$ ,"port:", portnr)
blockget=ByteAsc(MidStr(trans$,2,1,#ENCODING_RAW))*256+ByteAsc(MidStr(trans$,3,1,#ENCODING_RAW))
If (trans$<>"" And blockget = blockis)
SendUDPData(1, Ackn$ .. MidStr(trans$,2,2,#ENCODING_RAW) , ipadress2$ , portnr)
a$ = a$ .. MidStr(trans$,4,-1,#ENCODING_RAW )
blockis = blockis + 1
temp$="Anzahl Bytes/Block: " .. StrLen(trans$,#ENCODING_RAW) .. " akt.Block: " .. blockget .. " Insgesamt Bytes: " .. StrLen(a$,#ENCODING_RAW)
printstatus
EndIf
EndIf
If StrLen(trans$,#ENCODING_RAW) < 516
CloseUDPObject(1)
trans$=""
blockis = Nil
printstatus
EndIf
EndFunction
Function p_MenuFunc(msg)
Switch msg.action
Case "OnMenuSelect":
Switch msg.item
Case "file":
SaveFile
Case "get":
NetConn
Case "quit":
End
Case "about"
SystemRequest("Netzwerktests in Hollywood", "Netzwerktests in Hollywood", "O.K.")
EndSwitch
EndSwitch
EndFunction
Function p_ButtonFunc(msg)
DebugPrint ("Button Pressed !")
Switch button$[msg.id]
Case "Serv"
in$ = StringRequest("Server", "IP-Adress or Hostname" , ipadress$ )
If in$<>"" Then ipadress$ = in$
setipadress
Case "Remo"
in$ = StringRequest("Remotefile", "only the file to get" , data$ )
If in$<>"" Then data$ = in$
setdata
Case "GET "
NetConn
Case "File"
savename$=StringRequest("Savefile", "The complete filename (with path)" , savename$ )
If in$<>"" Then savename$ = in$
setfilename
Case "... "
savename$ = FileRequest("Select a file")
setfilename
Case "Save"
SaveFile
EndSwitch
EndFunction
SetFontColor(#BLACK)
SetFont("Arial", 16)
;Make the Buttons and GUI
buttonevents = {OnMouseUp = p_ButtonFunc, OnRightMouseUp = p_ButtonFunc}
ipy=35
day=80
MakeGagdet(2, 10, ipy, 350, 30,"Server")
MakeGagdet(2, 10, day, 350, 30,"Remotefile")
MakeGagdet(1, 10, 115, 80, 30,"GET")
SetFillStyle(#FILLNONE)
Box(5, 5, 380, 145, #GREEN)
TextOut(10,6,"[b][u]REMOTE[b][u]",{COLOR = #GREEN})
setipadress
setdata
SetFillStyle(#FILLNONE)
fny=190
MakeGagdet(2, 10,fny ,350, 30,"Filename:")
MakeGagdet(1, 10, 230, 30, 30,"...")
MakeGagdet(1, 10, 270, 80, 30,"Save")
setfilename
SetFillStyle(#FILLNONE)
Box(5, 155, 380, 160, #BLUE)
col=COLOR=$000000FF
TextOut(10,155,"[b][u]LOCAL[b][u]",{COLOR = #BLUE})
InstallEventHandler({OnMenuSelect = p_MenuFunc,OnReceiveUDPData = p_Receive})
; endless loop
Repeat
WaitEvent
Forever