Browse Source

Initial Source

Signed-off-by: Imhotheb <Info@Imhotheb.de>
master
Imhotheb 6 years ago
parent
commit
8375cee491
  1. 74
      ConnectionTest.pbp
  2. 2
      LICENSE
  3. 408
      Main.pb
  4. 3
      README.md
  5. 71
      Wnd.pbf

74
ConnectionTest.pbp

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.purebasic.com/namespace" version="1.0" creator="PureBasic 5.62 (Windows - x86)">
<section name="config">
<options closefiles="1" openmode="2" name="ConnectionTest"/>
</section>
<section name="data">
<explorer view="" pattern="0"/>
<log show="1"/>
<lastopen date="2018-11-18 18:10" user="Andy" host="MINAS"/>
</section>
<section name="files">
<file name="Main.pb">
<config load="1" scan="1" panel="1" warn="1" lastopen="1" panelstate="+"/>
<fingerprint md5="06a219f523b6bff8eeb67c4ed729c9a7"/>
</file>
<file name="Wnd.pbf">
<config load="1" scan="1" panel="1" warn="1" lastopen="1" panelstate="+"/>
<fingerprint md5="5faa0a245f63229d47e81d1568979e4b"/>
</file>
</section>
<section name="targets">
<target name="32-Bit Executable" enabled="1" default="1">
<inputfile value="Main.pb"/>
<outputfile value="..\ConnTest.exe"/>
<options thread="1" xpskin="1" debug="1"/>
<temporaryexe value="source"/>
<compilecount enable="1" value="60"/>
<buildcount enable="1" value="15"/>
<execonstant enable="1"/>
<versioninfo enable="1">
<field0 value="1.%yy%mm.%dd%BUILDCOUNT.%COMPILECOUNT"/>
<field1 value="1.%yy%mm.%dd%BUILDCOUNT.%COMPILECOUNT"/>
<field2 value="Imhotheb"/>
<field3 value="Connection Test"/>
<field4 value="1.%yy%mm.%dd%BUILDCOUNT.%COMPILECOUNT"/>
<field5 value="1.%yy%mm.%dd%BUILDCOUNT.%COMPILECOUNT"/>
<field6 value="Connection Test"/>
<field7 value="iConnTest"/>
<field8 value="%EXECUTABLE"/>
<field9 value="© Imhotheb"/>
<field13 value="Info@Imhotheb.de"/>
<field14 value="https://imhotheb.de"/>
<field15 value="VOS_NT"/>
<field16 value="VFT_APP"/>
</versioninfo>
</target>
<target name="64-Bit Executable" enabled="1" default="0">
<inputfile value="Main.pb"/>
<outputfile value="..\ConnTest_x64.exe"/>
<options thread="1" xpskin="1" debug="1"/>
<temporaryexe value="source"/>
<compilecount enable="1" value="54"/>
<buildcount enable="1" value="15"/>
<execonstant enable="1"/>
<versioninfo enable="1">
<field0 value="1.%yy%mm.%dd%BUILDCOUNT.%COMPILECOUNT"/>
<field1 value="1.%yy%mm.%dd%BUILDCOUNT.%COMPILECOUNT"/>
<field2 value="Imhotheb"/>
<field3 value="Connection Test"/>
<field4 value="1.%yy%mm.%dd%BUILDCOUNT.%COMPILECOUNT"/>
<field5 value="1.%yy%mm.%dd%BUILDCOUNT.%COMPILECOUNT"/>
<field6 value="Connection Test"/>
<field7 value="iConnTest"/>
<field8 value="%EXECUTABLE"/>
<field9 value="© Imhotheb"/>
<field13 value="Info@Imhotheb.de"/>
<field14 value="https://imhotheb.de"/>
<field15 value="VOS_NT"/>
<field16 value="VFT_APP"/>
</versioninfo>
</target>
</section>
</project>

2
LICENSE

@ -1,6 +1,6 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright © 2007 Free Software Foundation, Inc. <http s ://fsf.org/>
Copyright © 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for software and other kinds of works.

408
Main.pb

@ -0,0 +1,408 @@
EnableExplicit
XIncludeFile "Wnd.pbf"
If Not InitNetwork()
MessageRequester("Fehler", "Netzwerkfehler")
End
EndIf
Macro Version()
"V" + Str(1) + "." + FormatDate("%yy%mm.%dd", Date()) + Str(#PB_Editor_BuildCount) + "." + Str(#PB_editor_CompileCount)
EndMacro
Enumeration Events #PB_Event_FirstCustomValue
#EVENT_ThreadFinished
EndEnumeration
Enumeration Menu
#MENU_PopUp
EndEnumeration
Enumeration MenuItem
#MENUITEM_Copy
#MENUITEM_Cut
#MENUITEM_Paste
#MENUITEM_SelectAll
#MENUITEM_Undo
EndEnumeration
Structure ThreadData
ID.i
Exit.i
Url.s
Query.s
Format.i
Modus.i
GetRaw.i
Timeout.i
Interval.i
EndStructure
Global ThreadData.ThreadData
Global PopupMenuGadget
Procedure WriteLog(String.s, TimeStamp = #True)
If TimeStamp
AddGadgetItem(#EDIT_Log, -1, FormatDate("%yy-%mm-%dd %hh:%ii:%ss -> ", Date()) + String)
Else
AddGadgetItem(#EDIT_Log, -1, String)
EndIf
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
; NICHT in der DEMO-Version
SendMessage_(GadgetID(#EDIT_Log), #EM_SETSEL, -1, -1) ; Automatisch weiter scrollen
CompilerEndIf
; While WindowEvent() : Wend ; Quick'n Dirty
EndProcedure
Procedure.s CheckUrl(Url.s)
If FindString(Url, "://", 1, #PB_String_NoCase) < 1
Url = "none://" + Url
EndIf
ProcedureReturn Url
EndProcedure
Procedure.s GetQuery()
Protected Ret.s
Ret = GetGadgetText(#EDIT_Own)
Ret = RemoveString(Ret, #CR$)
Ret = RemoveString(Ret, #LF$)
Ret = UnescapeString(Ret)
ProcedureReturn Ret
EndProcedure
Procedure.s ReceiveHTTP(Url.s, Format = #PB_UTF8)
Protected Ret.s, *RecData, Size
WriteLog("Anfrage " + Url + " senden ...")
*RecData = ReceiveHTTPMemory(Url)
If *RecData
Size = MemorySize(*RecData)
Ret = PeekS(*RecData, Size, Format)
WriteLog(Str(Size) + " Bytes empfangen")
Else
WriteLog("Verbindungsfehler")
EndIf
ProcedureReturn Ret
EndProcedure
Procedure.s ReceiveRaw(Url.s, Query.s, Format = #PB_UTF8, Modus = #PB_Network_TCP|#PB_Network_IPv4, TimeOut = 5000)
Protected Server.s, Port, *Query, QueryBytes
Protected NetID, Bytes, *Buff, StartTime, Ret.s
Url=CheckUrl(Url)
Server.s = GetURLPart(Url, #PB_URL_Site)
Port = Val(GetURLPart(Url, #PB_URL_Port))
If Port = 0
Port = 80
EndIf
QueryBytes = StringByteLength(Query, Format)
*Query = AllocateMemory(QueryBytes + 2)
If *Query
PokeS(*Query, Query, -1, Format)
*Buff = AllocateMemory(100000) ; 100 KB Puffer
If *Buff
WriteLog("Verbinde mit " + Server + ":" + Str(Port) + " ...")
NetID = OpenNetworkConnection(Server, Port, Modus, TimeOut)
If NetID
WriteLog("Verbindung erfolgreich")
WriteLog("Sende Anfrage ...")
Bytes = SendNetworkData(NetID, *Query, QueryBytes)
WriteLog(Str(Bytes) + " Bytes gesendet")
WriteLog("Warte " + Str(TimeOut) + " ms auf Antwort ...")
Bytes = 0
StartTime = ElapsedMilliseconds()
Repeat
Select NetworkClientEvent(NetID)
Case #PB_NetworkEvent_Data
WriteLog("Empfange Daten ...")
Bytes = ReceiveNetworkData(NetID, *Buff, MemorySize(*Buff))
If Bytes
WriteLog(Str(Bytes) + " Bytes empfangen")
Ret = PeekS(*Buff, Bytes, Format|#PB_ByteLength)
Break
EndIf
Case #PB_NetworkEvent_Disconnect
WriteLog("Verbindung wurde getrennt")
Break
Default
If (ElapsedMilliseconds() - StartTime) > TimeOut
WriteLog("Timeout erreicht")
Break
Else
Delay(5)
EndIf
EndSelect
ForEver
CloseNetworkConnection(NetID)
Else
WriteLog("Verbindung fehlgeschlagen")
EndIf
FreeMemory(*Buff)
Else
WriteLog("Nicht genug freier Speicher")
Debug "ReceiveRaw: Nicht genug freier Speicher"
EndIf
FreeMemory(*Query)
Else
WriteLog("Nicht genug freier Speicher")
Debug "ReceiveRaw: Nicht genug freier Speicher"
EndIf
ProcedureReturn Ret
EndProcedure
Procedure THREAD_Receive(*TData.ThreadData)
Protected Ret.s, StartTime = ElapsedMilliseconds(), Run = #True, Loop
With *TData
Repeat
; Abrufen
If Run
WriteLog(RSet(#Empty$, 20, "=") + " AbfrageNr.: " + Str(Loop) + " " + RSet(#Empty$, 20, "="), #False)
If \GetRaw
Ret = ReceiveRaw(\Url, \Query, \Format, \Modus, \Timeout)
Else
Ret = ReceiveHTTP(\Url, \Format)
EndIf
If Ret <> #Empty$
WriteLog("Antwort vom Server: ")
WriteLog(RSet(#Empty$, 25, "-"), #False)
WriteLog(Ret, #False)
WriteLog(RSet(#Empty$, 25, "-"), #False)
EndIf
Run = #False
EndIf
; Intervallrechnung
If \Interval > 0
If (ElapsedMilliseconds() - StartTime) > \Interval
Loop + 1
Run = #True
StartTime = ElapsedMilliseconds()
EndIf
Else ; kein Interval, keine Wiederholung
Break
EndIf
; Beenden-Anforderung, Resourcen freigeben
If \Exit
Break
Else
Delay(10)
EndIf
ForEver
EndWith
PostEvent(#EVENT_ThreadFinished, #WND, #Null)
EndProcedure
Procedure ThreadCleanUp()
DisableGadget(#BTN_Start, #True)
If ThreadData\ID
ThreadData\Exit = #True
If IsThread(ThreadData\ID)
WriteLog("Warte auf Thread ...")
If WaitThread(ThreadData\ID, ThreadData\Timeout) = 0
WriteLog("Kill Thread ...")
KillThread(ThreadData\ID)
EndIf
EndIf
WriteLog(">>>>>>>>>> Thread beendet <<<<<<<<<<")
EndIf
ResetStructure(@ThreadData, ThreadData)
DisableGadget(#BTN_Start, #False)
EndProcedure
Procedure CALLBACK_Gadgets()
Protected EventType = EventType()
Protected EventGadget = EventGadget()
Select EventGadget
Case #BTN_Start
If GetGadgetState(#BTN_Start)
If GetGadgetState(#CHK_Repeat)
ThreadData\Interval = GetGadgetState(#SPIN_ms)
SetGadgetText(#BTN_Start, "STOP")
Else
ThreadData\Interval = 0
SetGadgetState(#BTN_Start, #False)
EndIf
ThreadData\Exit = #False
ThreadData\Url = GetGadgetText(#STR_Url)
ThreadData\Format = #PB_UTF8
ThreadData\GetRaw = GetGadgetState(#OPT_Own)
ThreadData\Modus = #PB_Network_TCP|#PB_Network_IPv4
ThreadData\Query = GetQuery()
ThreadData\Timeout = 10000
ThreadData\ID = CreateThread(@THREAD_Receive(), @ThreadData)
WriteLog(">>>>>>>>>> Starte Thread ... <<<<<<<<<<")
Else
ThreadData\Exit = #True ;ThreadCleanUp()
SetGadgetText(#BTN_Start, "START")
EndIf
Case #BTN_DelLog
SetGadgetText(#EDIT_Log, #Empty$)
Case #EDIT_Info
If EventType = #PB_EventType_RightClick
PopupMenuGadget = EventGadget
DisableMenuItem(#MENU_PopUp, #MENUITEM_Cut, #True)
DisableMenuItem(#MENU_PopUp, #MENUITEM_Paste, #True)
DisableMenuItem(#MENU_PopUp, #MENUITEM_Undo, #True)
DisplayPopupMenu(#MENU_PopUp, WindowID(#WND))
EndIf
Case #EDIT_Log
If EventType = #PB_EventType_RightClick
PopupMenuGadget = EventGadget
DisableMenuItem(#MENU_PopUp, #MENUITEM_Cut, #True)
DisableMenuItem(#MENU_PopUp, #MENUITEM_Paste, #True)
DisableMenuItem(#MENU_PopUp, #MENUITEM_Undo, #True)
DisplayPopupMenu(#MENU_PopUp, WindowID(#WND))
EndIf
Case #EDIT_Own
If EventType = #PB_EventType_RightClick
PopupMenuGadget = EventGadget
DisableMenuItem(#MENU_PopUp, #MENUITEM_Cut, #False)
DisableMenuItem(#MENU_PopUp, #MENUITEM_Paste, #False)
DisableMenuItem(#MENU_PopUp, #MENUITEM_Undo, #False)
DisplayPopupMenu(#MENU_PopUp, WindowID(#WND))
EndIf
Default
If GetGadgetState(#CHK_Repeat)
DisableGadget(#SPIN_ms, #False)
Else
DisableGadget(#SPIN_ms, #True)
EndIf
If GetGadgetState(#OPT_Own)
DisableGadget(#EDIT_Own, #False)
Else
DisableGadget(#EDIT_Own, #True)
EndIf
EndSelect
EndProcedure
Procedure CALLBACK_Menu()
Select EventMenu()
Case #MENUITEM_Undo
SendMessage_(GadgetID(PopupMenuGadget), #WM_UNDO, 0, 0)
Case #MENUITEM_Cut
SendMessage_(GadgetID(PopupMenuGadget), #WM_CUT, 0, 0)
Case #MENUITEM_Copy
SendMessage_(GadgetID(PopupMenuGadget), #WM_COPY, 0, 0)
Case #MENUITEM_Paste
SendMessage_(GadgetID(PopupMenuGadget), #WM_PASTE, 0, 0)
Case #MENUITEM_SelectAll
;lang = Len(GetGadgetText(EventGadget))
SendMessage_(GadgetID(PopupMenuGadget), #EM_SETSEL, 0, -1)
EndSelect
EndProcedure
Procedure CALLBACK_Wnd(hWnd, Msg, wParam, lParam)
If Msg = #WM_CONTEXTMENU
Select wParam
Case GadgetID(#EDIT_Info)
PostEvent(#PB_Event_Gadget, #WND, #EDIT_Info, #PB_EventType_RightClick)
Case GadgetID(#EDIT_Own)
PostEvent(#PB_Event_Gadget, #WND, #EDIT_Own, #PB_EventType_RightClick)
Case GadgetID(#EDIT_Log)
PostEvent(#PB_Event_Gadget, #WND, #EDIT_Log, #PB_EventType_RightClick)
EndSelect
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
Procedure Create_WND()
; Fenster öffnen und Standartwerte setzen
OpenWND()
SetWindowTitle(#WND, "Connection Test " + Version())
WindowBounds(#WND, WindowWidth(#WND), WindowHeight(#WND), #PB_Ignore, #PB_Ignore)
BindEvent(#PB_Event_SizeWindow, @ResizeGadgetsWND(), #WND)
BindEvent(#PB_Event_Gadget, @CALLBACK_Gadgets(), #WND)
BindEvent(#PB_Event_Menu, @CALLBACK_Menu(), #WND)
BindEvent(#EVENT_ThreadFinished, @ThreadCleanUp(), #WND)
SetWindowCallback(@CALLBACK_Wnd(), #WND)
CALLBACK_Gadgets()
SetGadgetText(#EDIT_Own,"GET /file.xxx HTTP/1.1\r\n" + #LF$ +
"Host: server\r\n" + #LF$ +
"Connection: close\r\n" + #LF$ +
;"User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0" + #LF$ +
"\r\n\r\n")
SetGadgetState(#OPT_Internal, #True)
SetGadgetState(#CHK_Repeat, #False)
SetGadgetState(#SPIN_ms, 5000)
If CreatePopupMenu(#MENU_PopUp)
MenuItem(#MENUITEM_Undo, "Rückgängig")
MenuBar()
MenuItem(#MENUITEM_Copy, "Kopieren")
MenuItem(#MENUITEM_Cut, "Ausschneiden")
MenuItem(#MENUITEM_Paste, "Einfügen")
MenuBar()
MenuItem(#MENUITEM_SelectAll, "Alles Auswählen")
EndIf
; Info hinzufügen
AddGadgetItem(#EDIT_Info, -1, "Escape-Sequenzen:")
AddGadgetItem(#EDIT_Info, -1, ~"\\a\tAscii: 7\tBeep")
AddGadgetItem(#EDIT_Info, -1, ~"\\b\tAscii: 8\tBackSpace")
AddGadgetItem(#EDIT_Info, -1, ~"\\t\tAscii: 9\tH-Tab")
AddGadgetItem(#EDIT_Info, -1, ~"\\n\tAscii: 10\tLineFeed")
AddGadgetItem(#EDIT_Info, -1, ~"\\v\tAscii: 11\tV-Tab")
AddGadgetItem(#EDIT_Info, -1, ~"\\f\tAscii: 12\tFormFeed")
AddGadgetItem(#EDIT_Info, -1, ~"\\r\tAscii: 13\tCarriageReturn")
AddGadgetItem(#EDIT_Info, -1, ~"\\\"\tAscii: 34\tDoubleQuote")
AddGadgetItem(#EDIT_Info, -1, ~"\\\\\tAscii: 92\tBackSlash")
EndProcedure
;_ INIT
Create_WND()
HideWindow(#WND, #False)
;_ MAIN
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
;Aufräumen
HideWindow(#WND, #True)
ThreadCleanUp()
; IDE Options = PureBasic 5.62 (Windows - x86)
; CursorPosition = 9
; Folding = LA9
; EnableXP
; CompileSourceDirectory
; EnableCompileCount = 0
; EnableBuildCount = 0
; EnableExeConstant

3
README.md

@ -1,2 +1,3 @@
# ConnectionTest
# ConnectionTest / iConnTest

71
Wnd.pbf

@ -0,0 +1,71 @@
; Form Designer for Purebasic - 5.62
; Warning: this file uses a strict syntax, if you edit it, make sure to respect the Form Designer limitation or it won't be opened again.
;
; This code is automatically generated by the FormDesigner.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures needs to be put in another source file.
;
Enumeration FormWindow
#WND
EndEnumeration
Enumeration FormGadget
#FRM_Url
#STR_Url
#FRM_Connect
#TXT_ms
#SPIN_ms
#CHK_Repeat
#OPT_Internal
#OPT_Own
#FRM_Log
#EDIT_Log
#BTN_Start
#EDIT_Own
#EDIT_Info
#Splitter_0
#BTN_DelLog
EndEnumeration
Declare ResizeGadgetsWND()
Procedure OpenWND(x = 0, y = 0, width = 490, height = 370)
OpenWindow(#WND, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_Invisible | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
FrameGadget(#FRM_Url, 10, 0, 470, 50, "Url")
StringGadget(#STR_Url, 20, 20, 450, 20, "Server/IP[:Port][/file.xxx]")
FrameGadget(#FRM_Connect, 10, 50, 470, 180, "Abfrage")
TextGadget(#TXT_ms, 420, 100, 30, 20, "ms")
SpinGadget(#SPIN_ms, 330, 100, 80, 20, 1, 99999, #PB_Spin_Numeric)
CheckBoxGadget(#CHK_Repeat, 310, 70, 160, 25, "Automatisch Wiederholen")
OptionGadget(#OPT_Internal, 20, 70, 250, 25, "Interne/cUrl Funktionen verwenden (HTTP)")
OptionGadget(#OPT_Own, 20, 100, 110, 25, "Eigene Abfrage:")
FrameGadget(#FRM_Log, 10, 230, 380, 130, "Log")
EditorGadget(#EDIT_Log, 20, 250, 360, 100, #PB_Editor_ReadOnly)
ButtonGadget(#BTN_Start, 400, 240, 80, 40, "Start", #PB_Button_Toggle)
EditorGadget(#EDIT_Own, 20, 130, 250, 90)
EditorGadget(#EDIT_Info, 279, 130, 191, 90, #PB_Editor_ReadOnly)
SplitterGadget(#Splitter_0, 20, 130, 450, 90, #EDIT_Own, #EDIT_Info, #PB_Splitter_Vertical)
SetGadgetState(#Splitter_0, 250)
ButtonGadget(#BTN_DelLog, 400, 290, 80, 30, "Log löschen")
EndProcedure
Procedure ResizeGadgetsWND()
Protected FormWindowWidth, FormWindowHeight
FormWindowWidth = WindowWidth(#WND)
FormWindowHeight = WindowHeight(#WND)
ResizeGadget(#FRM_Url, 10, 0, FormWindowWidth - 20, 50)
ResizeGadget(#STR_Url, 20, 20, FormWindowWidth - 40, 20)
ResizeGadget(#FRM_Connect, 10, 50, FormWindowWidth - 20, 180)
ResizeGadget(#TXT_ms, FormWindowWidth - 70, 100, 30, 20)
ResizeGadget(#SPIN_ms, FormWindowWidth - 160, 100, 80, 20)
ResizeGadget(#CHK_Repeat, FormWindowWidth - 180, 70, 160, 25)
ResizeGadget(#FRM_Log, 10, 230, FormWindowWidth - 110, FormWindowHeight - 240)
ResizeGadget(#EDIT_Log, 20, 250, FormWindowWidth - 130, FormWindowHeight - 270)
ResizeGadget(#BTN_Start, FormWindowWidth - 90, 240, 80, 40)
ResizeGadget(#Splitter_0, 20, 130, FormWindowWidth - 40, 90)
ResizeGadget(#BTN_DelLog, GadgetWidth(#Splitter_0) - 50, 290, 80, 30)
EndProcedure
Loading…
Cancel
Save

Impressum | Datenschutz