Jump to content

Problem with TCPReceive and Duration Time


Recommended Posts

Hi to all. I have this script, a server which accepts 2 simultaneous connection from client. Client send data by tcpsend then server receives by tcpreceive. When server receives data, it will connect remotely using VNC. then i have the function which calculates the time spent until the VNC window closes. Server successfully receives first connection. My problem is, when the next PC client sends data while server is active on first connection, server could not accept the connection. It will accept the connection when the window for VNC has been closed.

any idea how to do it? basically i just want to calculate the time until VNC window closes. appreciate anyone's bright idea.

thank you. script is like this...

#include <inet.au3>
#include <Constants.au3>
#include <GuiEdit.au3>
#include <GuiMenu.au3>
#include <WinAPI.au3>

Opt("TrayMenuMode", 1)
Opt("WinTitleMatchMode", 2)
Opt('MustDeclareVars', 0)
Opt("GUIOnEventMode", 1)

Global $CURRENT_SOCKET 
Global $CONNECTED_SOCKET[3]
Global $TCP_SERVER
Global $SPLIT, $RECV

$accept = TrayCreateItem("Accept")
TrayCreateItem("")
$close = TrayCreateItem("Close")

TraySetState()


While 1
    
$msg = TrayGetMsg()
    Select      
        Case $msg = $accept         
            Connect()           
        Case $msg = $close
            Close()
    EndSelect
    
    $CONNECTED_SOCKET[$CURRENT_SOCKET] = TCPAccept($TCP_SERVER)         
        If $CONNECTED_SOCKET[$CURRENT_SOCKET] <> -1 Then            
            
            $CURRENT_SOCKET += 1            
            
            If $CURRENT_SOCKET = 2 Then 
                
                TCPCloseSocket($TCP_SERVER)                 
                Sleep(100)
                MsgBox(64, "Warning!", "Full!")         
            EndIf
        EndIf       
         
    For $INDEX = 0 To 2
        
        $RECV = TCPRecv($CONNECTED_SOCKET[$INDEX],512)      
        If $RECV <> "" Then 
            
            $SPLIT = StringSplit($RECV, "|",0)          
            If IsArray($SPLIT) Then 
                Remote()
                Duration()          
            EndIf       
        EndIf
         
    Next    
Wend

Func Connect()  
    $TCP = TCPStartup()
    $TCP_SERVER = TCPListen(@IPAddress1,2000,16)    
    $CURRENT_SOCKET = 0 
ENdFunc


Func Duration()
    
    AutoItSetOption("WinTitleMatchMode", 4)
    Dim $h, $m, $s

    If WinExists("classname=rfb::win32::DesktopWindowClass", "") Then
        WinSetState("classname=rfb::win32::DesktopWindowClass", "", @SW_SHOWMINNOACTIVE)
    EndIf

    WinWait("classname=rfb::win32::DesktopWindowClass", "")
    $title = WinGetTitle("classname=rfb::win32::DesktopWindowClass")

    $start = _NowTime()
    $timer = TimerInit()

    WinWaitClose($title, "")    


    $timer = TimerDiff($timer)
    $end = _NowTime()

    _TicksToTime(Int($timer), $h, $m, $s)
;_TicksToTime(Int(TimerDiff($timer)), $Hour, $Mins, $Secs)
    $dur = StringFormat("%02i:%02i:%02i", $h, $m, $s)   

    Return ($start & "|" & $end & "|" & $dur)

EndFunc  ;==>VNCTime2


Func Remote()
    $PC = $SPLIT[2] 
    $VNC_Path = "C:\Program Files\RealVNC\VNC4\vncviewer.exe "
    $VNC_Dir = "C:\Program Files\RealVNC\VNC4\"
    If Not FileExists($VNC_Path) Then
        MsgBox(16, "Program Error", "WinVNC is not installed")
    Else
        Run($VNC_Path & $PC, $VNC_Dir)
    EndIf   
EndFunc


Func Close()    
    Exit
EndFunc
Link to comment
Share on other sites

I don't see why you shouldn't be able to receive anything with TCPAccept when VNC is running. I have a script which automatically start and stops UVNC and I check that UVNC is running using ProcessExists("winvnc.exe"). Maybe you could do something like that to decide when to start a timer or note the start time, and when to stop the timer or note the ending time.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I don't see why you shouldn't be able to receive anything with TCPAccept when VNC is running. I have a script which automatically start and stops UVNC and I check that UVNC is running using ProcessExists("winvnc.exe"). Maybe you could do something like that to decide when to start a timer or note the start time, and when to stop the timer or note the ending time.

thanks martin for the reply. thats why i'm stuck to this. i cannot receive from client until only i close the VNC window. i'm thinking that Winwaitclose command. the script is waiting for that command to be finished so that i can receive data from client. i have tested to remove the Duration function which waits for the VNC window to close, and was successful to receive two simultaneous client connections.

i haven't tried to use the ProcessClose command, but i still have to issue ProcesswaitClose command for my script to detect that process has been closed. i am thinking to calcualte the time difference between the time started and time end. something like time start - time end but could not get any formula to calculate time difference in seconds and minutes...

any idea?

Link to comment
Share on other sites

I don't see why you shouldn't be able to receive anything with TCPAccept when VNC is running. I have a script which automatically start and stops UVNC and I check that UVNC is running using ProcessExists("winvnc.exe"). Maybe you could do something like that to decide when to start a timer or note the start time, and when to stop the timer or note the ending time.

hi martin. mind to share that script? thanks...

Link to comment
Share on other sites

  • 3 months later...

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...