Jump to content

Hello, help me this error (TCP send picture )


Recommended Posts

Try this:

server.au3:

TCPStartup()
$ip='192.168.1.4'
$listen=TCPListen($ip,4444)

Do
    $socket=TCPAccept($listen)
    $data=TCPRecv($socket,1342177280)

Until $data<>Null
$op=FileOpen('khang.jpg',18)
FileWrite($op,$data)

client.au3

TCPStartup()
$ip='192.168.1.4'

$op=FileOpen('IMG_2474.JPG',16)
$connect=TCPConnect($ip,4444)
TCPSend($connect,FileRead($op))
TCPSend($connect,Null)
FileClose($op)

 

TD :)

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

TCPStartup()
$ip=@IPAddress1
$listen=TCPListen($ip,4444)

Do
    $socket=TCPAccept($listen)
    $data=TCPRecv($socket,1342177280)

Until $data="Complete"
$op=FileOpen('khang.jpg',18)
FileWrite($op,$data)
FileClose($op)


 

TCPStartup()
$ip=@IPAddress1

$op=FileOpen('IMG.jpg',16)
$connect=TCPConnect($ip,4444)
TCPSend($connect,FileRead($op))
TCPSend($connect,"Complete")
FileClose($op)

is this right?.....not work :<

Link to comment
Share on other sites

Ahhh.... I am still experimenting but I ran out of time :(, I need to go to bed. I will try to solve this issue tomorrow

 

TD :)

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

you can send big file ;)

server

TCPStartup()

Global $ip = @IPAddress1
Global $Port = 4444
Global $sSocket = -1

Global $LenSendData = 1024 * 1024 
Global $PackSendfile = "[PackSendfile]"
Global $EndPackSendfile = "[EndPackSendfile]"
Global $lenEndPackSendfile = StringLen($EndPackSendfile)
Global $RecevFileok = "[RecevFileok]"
Global $Spdata = "[#Spdata]"

Global $listen = TCPListen($ip, $Port)
Global $sSocket = _Tcp_Get_Connection($listen)

While True
    Sleep(100)
    _Getcmdtype($sSocket)
WEnd

Func _Getcmdtype($tsSocket)
    Local $Getcmdtype = TCPRecv($tsSocket, 999)
    If $Getcmdtype = "" Then Return False
    Select
        Case StringInStr($Getcmdtype, $PackSendfile) > 0
            Local $Getfileinfo = StringSplit($Getcmdtype, $Spdata, 1)
            If @error Then Return False
            Local $Filesize = $Getfileinfo[2]
            Local $cSavepath = FileSaveDialog("Choose a filename...", @WorkingDir, "All (*.*)", 18, "test")
            If @error Then Return _Tcp_Exit()
            MsgBox(0, "", _Getdisplaysize(_Tcp_Rcv_File($tsSocket, $Filesize, FileGetShortName($cSavepath))) & " it was rcv")
            _Tcp_Exit()
    EndSelect
EndFunc   ;==>_Getcmdtype

Func _Tcp_Rcv_File($sSocket, $Filesize, $cSavepath)
    Local $op, $Binfile, $binlen, $Timer, $tbinlen, $ps
    TCPSend($sSocket, $RecevFileok)
    $op = FileOpen($cSavepath, 18)
    ProgressOn("Progress Meter", "Receive state", "Start",default,default,16)
    $Timer = TimerInit()
    Do
        $Binfile = ""
        Do
            $Binfile &= TCPRecv($sSocket, $LenSendData)
        Until StringRight($Binfile, $lenEndPackSendfile) = $EndPackSendfile
        $Binfile = StringSplit($Binfile, $EndPackSendfile, 1)
        $Binfile = $Binfile[1]
        $binlen += BinaryLen($Binfile)
        FileWrite($op, $Binfile)
        TCPSend($sSocket, $RecevFileok)
        
        If TimerDiff($Timer) >= 1000 Then
            $Rate = $binlen - $tbinlen
            $ps = ($binlen / $Filesize) * 100
            $tbinlen = $binlen
            ProgressSet(Int($ps), "Receive " & _Getdisplaysize($binlen) & " Of " & _Getdisplaysize($Filesize) & " " & Int($ps) & " % Rate " & _Getdisplaysize($Rate))
            $Timer = TimerInit()
        EndIf
        
    Until $Filesize = $binlen
    ProgressOff()
    FileClose($op)
    Return $binlen
EndFunc   ;==>_Tcp_Rcv_File

Func _Tcp_Get_Connection($sSocketlisten)
    Local $stSocket
    Do
        $stSocket = TCPAccept($listen)
    Until $stSocket <> -1
    Return $stSocket
EndFunc   ;==>_Tcp_Get_Connection

Func _Tcp_Exit()
    TCPCloseSocket($listen)
    TCPCloseSocket($sSocket)
    TCPShutdown()
    Exit
EndFunc   ;==>_Tcp_Exit

Func _Getdisplaysize($isize)
    If $isize < 1 Then Return 0
    Local $abytes[5] = [' Bytes', ' Kb', ' Mb', ' Go', ' Tb']
    For $i = 4 To 1 Step -1
        If $isize >= 1024 ^ $i Then Return Round($isize / 1024 ^ $i, 1) & $abytes[$i]
    Next
    Return $isize & $abytes[0]
EndFunc   ;==>_Getdisplaysize

 

client

TCPStartup()

Global $ip = @IPAddress1
Global $Port = 4444

Global $LenSendData = 1024 * 1024 
Global $PackSendfile = "[PackSendfile]"
Global $EndPackSendfile = "[EndPackSendfile]"
Global $RecevFileok = "[RecevFileok]"
Global $Spdata = "[#Spdata]"

Global $Connect = _Tcp_Clien_Connect($ip, $Port)

Global $mFilepath = FileOpenDialog("Select a file..", @WorkingDir & "\", "All (*.*)", 1)
If Not @error Then MsgBox(0, "", _Getdisplaysize(_Tcp_Send_file($Connect, FileGetShortName($mFilepath))) & " it was sent")

TCPCloseSocket($Connect)
TCPShutdown()

Func _Tcp_Send_file($stSocket, $mFilepath)
    Local $op, $Iread, $rcv, $binlen, $Filesize, $Timer, $tbinlen, $ps, $zError = False
    $Filesize = FileGetSize($mFilepath)
    TCPSend($stSocket, $PackSendfile & $Spdata & $Filesize)
    Do
        $rcv &= TCPRecv($stSocket, 24)
    Until $rcv = $RecevFileok
    $op = FileOpen($mFilepath, 16)
    ProgressOn("Progress Meter", "Send state", "Start",default,default,16)
    $Timer = TimerInit()
    While True
        $Iread = FileRead($op, $LenSendData)
        If @error Then ExitLoop
        TCPSend($stSocket, $Iread & $EndPackSendfile)
        $binlen += BinaryLen($Iread)
        $rcv = ""
        Do
            $rcv &= TCPRecv($stSocket, 24)
        Until $rcv = $RecevFileok
        
        If TimerDiff($Timer) >= 1000 Then
            $Rate = $binlen - $tbinlen
            $ps = ($binlen / $Filesize) * 100
            $tbinlen = $binlen
            ProgressSet(Int($ps), "Sent " & _Getdisplaysize($binlen) & " Of " & _Getdisplaysize($Filesize) & " " & Int($ps) & " % Rate " & _Getdisplaysize($Rate))
            $Timer = TimerInit()
        EndIf
        
    WEnd
    ProgressOff()
    FileClose($op)
    Return $binlen
EndFunc   ;==>_Tcp_Send_file

Func _Tcp_Clien_Connect($sIp, $mPort)
    Local $sSocket
    Do
        Sleep(100)
        $sSocket = TCPConnect($sIp, $mPort)
    Until $sSocket <> -1
    Return $sSocket
EndFunc   ;==>_Tcp_Clien_Connect

Func _Getdisplaysize($isize)
    If $isize < 1 Then Return 0
    Local $abytes[5] = [' Bytes', ' Kb', ' Mb', ' Go', ' Tb']
    For $i = 4 To 1 Step -1
        If $isize >= 1024 ^ $i Then Return Round($isize / 1024 ^ $i, 1) & $abytes[$i]
    Next
    Return $isize & $abytes[0]
EndFunc   ;==>_Getdisplaysize

 

Link to comment
Share on other sites

ok,

try this

TCPStartup()
$ip = @IPAddress1
$listen = TCPListen($ip, 4444)

Local $data, $socket = -1

Do
    If $socket = -1 Then
        $socket = TCPAccept($listen)
    EndIf
    If $socket <> -1 Then
        $data &= TCPRecv($socket, 1024 * 1024)
    EndIf
Until StringRight($data, 8) = "Complete"

TCPSend($socket, "Complete")

$data = StringTrimRight($data, 8)

$op = FileOpen('khang.jpg', 18)
FileWrite($op, $data)
FileClose($op)

client

TCPStartup()
$ip = @IPAddress1

Do
    $connect = TCPConnect($ip, 4444)
Until $connect <> -1

$op = FileOpen('IMG.jpg', 16)
TCPSend($connect, FileRead($op) & "Complete")
FileClose($op)

Do
    Sleep(1)
Until TCPRecv($connect, 8) = "Complete"

 

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