Jump to content

Recommended Posts

Posted

Hi

here is my code i have problem realated receiving data Properly

how i can exitloop after writing file in func _tcprecv() and btn1 button stop responding after on click

#include <GUIConstants.au3>

Dim $ConnectedSocket = -1
Dim $szServerPC = @ComputerName
Dim $szIPConvert = TCPNameToIP($szServerPC)

Opt("GUICoordMode", 1)
GUICreate("File Download Client", 600,500)
Dim $edit = GUICtrlCreateEdit("",100,150,300,100)
Dim $szIPADDRESS = GUICtrlCreateInput ($szIPConvert, 100,  30, 150, 20)
Dim $nPORT = GUICtrlCreateInput ("5110", 100,  60, 150, 20)
$filepath = GUICtrlCreateInput (@HomeDrive&"\"&'MyFile.txt', 100,  100, 150, 20)
GUICtrlCreateLabel ("Remote Ip:",  30, 32)
GUICtrlCreateLabel ("Port:",  30, 60)
GUICtrlCreateLabel ("Status:",  30, 150)
GUICtrlCreateLabel ("File Path:",  30, 100)
$btn1 = GUICtrlCreateButton("Connect", 300, 45, 100)
$btn2 = GUICtrlCreateButton("Download", 300, 95, 100)

GUISetState()
TCPStartUp()

Dim $ConnectedSocket = -1
Dim $buffer = ""

While 1
    
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
Case $msg = $GUI_EVENT_MINIMIZE
Case $msg = $GUI_EVENT_MAXIMIZE
Case $msg = $btn1
call ("_TcpConnection")
Case $msg = $btn2
call ("_tcprecv")
EndSelect

WEnd



Func _tcprecv()

While 1
$buffer = TCPRecv( $ConnectedSocket, 2048)
GUICtrlSetData($edit, " > " & $buffer & @CRLF & GUICtrlRead($edit))
$filewrite = FileWrite(GUICtrlRead($filepath),$buffer)
Wend

EndFunc

func _TcpConnection()
    
ConsoleWrite(GUICtrlRead($szIPADDRESS) & @CRLF & GUICtrlRead($nPORT) & @crlf)
$ConnectedSocket = TCPConnect(GUICtrlRead($szIPADDRESS), GUICtrlRead($nPORT) )
if $ConnectedSocket = -1 then 
GUICtrlSetData($edit, " > " & "No Connection Result" & " " & $ConnectedSocket & @CRLF & GUICtrlRead($edit))
Else
GUICtrlSetData($edit, " > " & "Connection Successful" & " " & $ConnectedSocket & @CRLF & GUICtrlRead($edit))
EndIf

EndFunc
Posted (edited)

Func _tcprecv()

   While 1
        $buffer = TCPRecv( $ConnectedSocket, 2048)
        GUICtrlSetData($edit, " > " & $buffer & @CRLF & GUICtrlRead($edit))
        $filewrite = FileWrite(GUICtrlRead($filepath),$buffer)
         If not @error then exitloop 
   Wend
EndFunc

is that what you are talking about?

I don't understand what you mean by stop responding after button click?

Edited by acidfear
Posted (edited)

Hi this function works fine but when i click on button its not having proper data stream

Func _tcprecv()

   While 1
        $buffer = TCPRecv( $ConnectedSocket, 2048)
        GUICtrlSetData($edit, " > " & $buffer & @CRLF & GUICtrlRead($edit))
        $filewrite = FileWrite(GUICtrlRead($filepath),$buffer)
         If not @error then exitloop 
   Wend
EndFunc

can we use do until ?

like

Func _tcprecv()
 do 
        $buffer = TCPRecv( $ConnectedSocket, 2048)
        GUICtrlSetData($edit, " > " & $buffer & @CRLF & GUICtrlRead($edit))
        $filewrite = FileWrite(GUICtrlRead($filepath),$buffer)
Until buffer >  ""
EndFunc

but again its not exiting loop

need help

Edited by autoitxp
Posted (edited)

Hi

Its not Receiving complete data stream and Function _tcprecv() not useable after click .

Edited by autoitxp

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
×
×
  • Create New...