Jump to content

TcpRecv Need Help


Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

hey this is general support forum and no one is responding.

...

$buffer = TCPRecv( $ConnectedSocket,  2048)
   If @error Then ExitLoop
If $buffer <> "" Then 
GUICtrlSetData($edit, " > " & $buffer & @CRLF & GUICtrlRead($edit))
       $filewrite = FileWrite(GUICtrlRead($filepath),$buffer)
endif

Does this works?

Edited by c4nm7
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...