Jump to content

Listview Help


Recommended Posts

Hi to all. I have this script on which clients send data using TCPSend for every successful connection. TCP Server monitor/tracks this connection using the LIstview GUI. Client server successfully connects and recorded by the server in the Listview GUI. My problem is that, i wanted to save each client connection into something like to write in log file or ini file. Such case, if i want to trace back the connection, i have this log to be read by the Listview GUI.

I was able to use the Iniwrite but it saves only one connection that's why i'm thinking to use another way on how i will save the connection into a log then it will be read by the LIstview GUI.

Here is what i have right now.

Client Code

HotKeySet('a', 'Connect')

Global $socket

Go()

Func Go()
    TCPStartup()
    While 1
        Sleep(500)
    WEnd
EndFunc

Func Connect()

    $socket = TCPConnect("192.168.1.5", 7000)   

    If $socket = -1 Then
                
            
        For $a=1 To 1
            Sleep(500)
            ConsoleWrite('Reconnecting in: ' & $a & ' second(s)' & @CRLF)
        Next
                        
    Else
        
        TCPSend($socket,@IPAddress1 & " | " & @ComputerName & " | " & @UserName)        
                
    EndIf
EndFunc

Part of the Server code is this....

For $INDEX = 0 To $CONNECTED_SOCKET 
                        $RECV = TCPRecv($CONNECTED_SOCKET[$CONNECTED_SOCKET],512)       
                        If $RECV <> "" Then             
                            $SPLIT2 = StringSplit($RECV, "|",0)
                            If IsArray($SPLIT2) Then                                                           
                                If $SPLIT2[0] = 3 Then
                                $time = @HOUR & ":" & @MIN & ":" & @SEC
                                $date = @MDAY & "/" & @MON & "/" & @YEAR
                                $tmp = $SPLIT2[1] & "|" & $SPLIT2[2] & "|" & $SPLIT2[3]                                     
                                                                       
                                 $log &= $tmp & @CRLF                                                                                                           
                                 GUICtrlCreateListViewItem($tmp, $Listview1)
                                                                                                                                
                                 IniWrite(@DesktopDir & "\log.ini", "LOGLIST", "LOG", $log)
                                                                                                
                EndIf
           EndIf
      EndIf
Next

Func Listview()
    $inilog = IniRead(@DesktopDir & "\log.ini", "LOGLIST", "LOG", "")   
    $ListviewGUILast = GUICreate("Connection Log", 547, 150, -1, -1, $WS_SYSMENU)   
    GUISetOnEvent($GUI_EVENT_CLOSE, "CloseGUILog")
    $Listview1 = GUICtrlCreateListView("", 10, 10, 520, 100)
    _GUICtrlListView_AddColumn ($ListView1, "IP Address", 120, 2)
    _GUICtrlListView_AddColumn ($ListView1, "Computer Name", 100, 2)
    _GUICtrlListView_AddColumn ($ListView1, "User ID", 100, 2)
;GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Connectlast")
    GUICtrlSetData($Listview1, $inilog)
;GUICtrlCreateListViewItem($inilog, $Listview1)             
    GUISetState(@SW_SHOW)
;GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
EndFunc

Func CloseGUILog()
    GUIDelete()
EndFunc

Appreciate anyone's ideas and suggestions...

Thank you

Link to comment
Share on other sites

hi to all m8s. anyone who has an idea with this? basically data that client will send will be saved into a text file or ini file. data will be delimited by "|". then if i will open the Listview, it will load that data from ini or text file. just having trouble how will i set the data into Listview.

appreciate all your help and ideas. thank you.

Link to comment
Share on other sites

hi to all m8s. anyone who has an idea with this? basically data that client will send will be saved into a text file or ini file. data will be delimited by "|". then if i will open the Listview, it will load that data from ini or text file. just having trouble how will i set the data into Listview.

appreciate all your help and ideas. thank you.

3 lines need changing

;change
IniWrite(@DesktopDir & "\log.ini", "LOGLIST", "LOG", $log)
;to 
FileWriteLine(@DesktopDir & "\log.ini", $log)

;change
$inilog = IniRead(@DesktopDir & "\log.ini", "LOGLIST", "LOG", "")
;to 
$inilogarray = StringSplit(FileRead(@DesktopDir & "\log.ini"), @CRLF, 1)

;change
GUICtrlSetData($Listview1, $inilog)
;to 
While $i <= $inilogarray[0]
    $i += 1
    GUICtrlSetData($Listview1, $inilog)
WEnd
Edited by Quual
Link to comment
Share on other sites

3 lines need changing

;change
IniWrite(@DesktopDir & "\log.ini", "LOGLIST", "LOG", $log)
;to 
FileWriteLine(@DesktopDir & "\log.ini", $log)

;change
$inilog = IniRead(@DesktopDir & "\log.ini", "LOGLIST", "LOG", "")
;to 
$inilogarray = StringSplit(FileRead(@DesktopDir & "\log.ini"), @CRLF, 1)

;change
GUICtrlSetData($Listview1, $inilog)
;to 
While $i <= $inilogarray[0]
    $i += 1
    GUICtrlSetData($Listview1, $inilog)
WEnd

Hi Quual. Thanks for idea. But have tried to changed as you suggested. But when i load the listview gui, there is no data that is loaded.

here is the edited script for the listview....

Func Listview()
    Local $i
;$inilog = IniRead(@DesktopDir & "\log.ini", "LOGLIST", "LOG", "")
    $inilogarray = StringSplit(FileRead(@DesktopDir & "\log.ini"), @CRLF, 1)    
    $ListviewGUILast = GUICreate("Connection Log", 547, 150, -1, -1, $WS_SYSMENU)   
    GUISetOnEvent($GUI_EVENT_CLOSE, "CloseGUILog")
    $Listview1 = GUICtrlCreateListView("", 10, 10, 520, 100)
    _GUICtrlListView_AddColumn ($ListView1, "IP Address", 120, 2)
    _GUICtrlListView_AddColumn ($ListView1, "Computer Name", 100, 2)
    _GUICtrlListView_AddColumn ($ListView1, "User ID", 100, 2)
    _GUICtrlListView_AddColumn ($Listview1, "Connect Time", 100, 2)
    _GUICtrlListView_AddColumn ($Listview1, "Connect Date", 100, 2)
    GUISetState(@SW_SHOW)
    While $i <= $inilogarray[0]
    $i += 1 
    GUICtrlSetData($Listview1, $inilogarray); i changed it since i received error on this part GUICtrlSetData($Listview1, $inilog)
    WEnd    
EndFunc
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...