LoadStar Posted March 6, 2015 Share Posted March 6, 2015 I am trying to listen to a connection over telnet... I can send data, but I am having trouble finding a solution to receiving a response. Here is what I am working on: expandcollapse popup#include <GUIConstants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <File.au3> #include <GuiListView.au3> #include <EditConstants.au3> HotKeySet("{INSERT}", "_easteregg") HotKeySet("{F1}", "_debugwindow") Global $ainput Global $file = "C:\SimpleOpensClient\messages\messagequeue.txt" Global $time = "" Global $status_text = "" Global $lastaction_text = "No last action." Global $ChyronIP = tcpconnect("192.168.1.106", "23") Global $TCPRecv = TCPRecv($ChyronIP,"5000") Global $debug_text = "" Global $section Global $time = @HOUR & ":" & @MIN & ":" & @SEC #Region ;~ Main Window $form1_1 = GUICreate("Simple Opens Client 1.5", 803, 529, 458, 314) $listview1 = GUICtrlCreateListView("Messages", 10, 120, 781, 401) GUICtrlSendMsg(-1, $lvm_setcolumnwidth, 0, 50) $listview1_0 = GUICtrlCreateListViewItem("aInput[i]", $listview1) $listview1_1 = GUICtrlCreateListViewItem("aInput[i]", $listview1) $button2 = GUICtrlCreateButton("Refresh", 10, 70, 250, 46) $button3 = GUICtrlCreateButton("Push Messages", 270, 70, 260, 45) $button4 = GUICtrlCreateButton("Clear", 540, 70, 250, 45) $label1 = GUICtrlCreateLabel("", 540, 10, 247, 42, $ss_center) GUICtrlSetFont(-1, 32, 400, 0, "MS Sans Serif") GUICtrlSetColor(-1, 65280) GUICtrlSetBkColor(-1, 0) GUICtrlSetResizing(-1, $gui_dockhcenter + $gui_dockvcenter) $status = GUICtrlCreateLabel("Status:" & $status_text, 10, 10, 517, 27) $lastaction = GUICtrlCreateLabel("Last Action:" & $lastaction_text, 10, 50, 520, 17) GUISetState(@SW_SHOW) _guictrllistview_setcolumnwidth($listview1, 0, 600) ;~ Easter egg $easteregg = GUICreate("Administrator Section", 251, 99, -1, -1) $passwordedit = GUICtrlCreateInput("password", 8, 32, 233, 21, $es_password) $buttonok = GUICtrlCreateButton("&OK", 86, 64, 75, 25) $buttoncancel = GUICtrlCreateButton("&Cancel", 167, 64, 75, 25) $enterpasslabel = GUICtrlCreateLabel("Enter password", 8, 12, 77, 17, 0) GUISetState(@SW_HIDE) ;~ Console Window $consolewindow = GUICreate("Debug Console", 674, 438, 340, 402, $WS_BORDER, @SW_HIDE) $consoledebug = GUICtrlCreateEdit("", 0, 0, 673, 417, BitOR($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY)) GUICtrlSetData(-1, $debug_text) GUISetState(@SW_HIDE) #EndRegion TCPStartup() _get() WinActivate("Simple Opens Client 1.5", "") While 1 $status_text = "Idle." _writetostatus() $time = @HOUR & ":" & @MIN & ":" & @SEC GUICtrlSetData($label1, $time) Sleep(50) $nmsg = GUIGetMsg() Switch $nmsg Case $gui_event_close TCPShutdown() Exit Case $button2 $lastaction_text = "Refresh" GUICtrlSetData($lastaction, "Last Action: " & $lastaction_text & " @ " & $time) _get() Case $button3 $lastaction_text = "Push" GUICtrlSetData($lastaction, "Last Action: " & $lastaction_text & " @ " & $time) _pushmessages() Case $button4 $lastaction_text = "Clear" GUICtrlSetData($lastaction, "Last Action: " & $lastaction_text & " @ " & $time) _clear() Case $buttonok If GUICtrlRead($passwordedit) == "secret" Then $nbbo = GUICreate("NO BOOTY", 204, 206, 217, 145) $pic1 = GUICtrlCreatePic("\\192.168.1.17\SimpleOpens\images\nbbo.bmp", 0, 0, 201, 201) GUISetState(@SW_SHOW) Sleep(5000) GUIDelete($nbbo) GUIDelete($easteregg) Else MsgBox(0, "Access Denied", "Incorrect password.") EndIf Case $buttoncancel GUIDelete($easteregg) EndSwitch WEnd Func _get() $section = "Get" _GUICtrlListView_DeleteAllItems($ListView1) $status_text = "Copying new information." _writetostatus() $UrlDownload = "http://192.168.1.17/messagequeue.txt" ;DL link $Directory = "C:\SimpleOpensClient\messages\messagequeue.txt" ;Name of your file FileDelete($Directory) Local $download = InetGet($UrlDownload, $Directory,0,1) Do Sleep(100) $debug_text = "[Get] Downloading messagequeue.txt from http://192.168.1.17..." _writetoconsole() Until InetGetInfo($download, 2) ;Checks to see if $download is completed (param 2) InetClose($download) RunWait($Directory) ;it will pause the script untill the process of the downloaded file is finished $debug_text = "[Get] Download finished." GUICtrlSetData($consoledebug, "[" & $time & "]" & " - " & $debug_text & @CRLF, 1) _filereadtoarray($file, $ainput) $status_text = "New information copied." _writetostatus() For $i = 1 To UBound($ainput) - 1 $status_text = "Writing information to list." GUICtrlSetData($status, "Status: " & $status_text) GUICtrlCreateListViewItem($ainput[$i], $listview1) Next EndFunc Func _clear() $section = "Clear" TCPStartup() $status_text = "Clearing data." _writetostatus() _guictrllistview_deleteallitems($listview1) $ChyronIP = tcpconnect("192.168.1.106", "23") Do Sleep(100) $debug_text = "Trying to connect to Chyron..." _writetoconsole() Until $ChyronIP <> "-1" $debug_text = "Connected." _writetoconsole() TCPSend($ChyronIP, "E\Delete8000\\" & @CRLF) $debug_text = "Delete8000 sent." _writetoconsole() Sleep(100) $debug_text = ("Disconnecting...") _writetoconsole() TCPShutdown() $debug_text = ("Disconnected.") _writetoconsole() EndFunc Func _pushmessages() $section = "PushMessages" TCPStartup() $ChyronIP = tcpconnect("192.168.1.106", "23") Do Sleep(100) $debug_text = "Trying to connect to Chyron..." _writetoconsole() Until $ChyronIP <> "-1" $debug_text = "Connected." _writetoconsole() TCPSend($ChyronIP, "E\Delete8000\\" & @CRLF) $debug_text = "Delete8000 sent." _writetoconsole() _filereadtoarray($file, $ainput) For $i = 1 To UBound($ainput) - 1 TCPSend($ChyronIP, $ainput[$i] & @CRLF) $debug_text = ("Sending: " & "''" & $ainput[$i] & "''") $status_text = ("Sending: " & $ainput[$i]) _writetostatus() _writetoconsole() Sleep(10) Next $debug_text = ("Disconnecting...") _writetoconsole() TCPShutdown() $debug_text = ("Disconnected.") _writetoconsole() EndFunc Func _easteregg() #Region ### START Koda GUI section ### Form= $easteregg = GUICreate("Administrator Section", 251, 99, -1, -1) $passwordedit = GUICtrlCreateInput("password", 8, 32, 233, 21, $es_password) $buttonok = GUICtrlCreateButton("&OK", 86, 64, 75, 25) $buttoncancel = GUICtrlCreateButton("&Cancel", 167, 64, 75, 25) $enterpasslabel = GUICtrlCreateLabel("Enter password", 8, 12, 77, 17, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### EndFunc Func _writetostatus() GUICtrlSetData($status, "Status: " & $status_text) EndFunc Func _writetoconsole() GUICtrlSetData($consoledebug, "[" & $time & "]" & " - " & "[" & $section & "]" & " " &$debug_text & @CRLF, 1) EndFunc Func _debugwindow() If WinGetState($consolewindow, 7) = 7 Then WinSetState($consolewindow, "", @SW_HIDE) Return ElseIf WinGetState($consolewindow, 5) = 5 Then WinSetState($consolewindow, "", @SW_SHOW) WinActivate($form1_1) Return EndIf EndFunc The responses I am expecting is a "*" the server uses as an acknowledgement of the command. Should I create a new function and call it in the While loop? I would like to monitor the connections at all times if possible. Also tips on how to clear up this mess would be appreciated as well Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now