Jump to content

help with max length string


Recommended Posts

Hi, I'm new on the forum! :)

This is my first post :P

I've made a script that download html source code of this page: http://www.tre.it/selfcare/areaclienti133/..._ITA_LOGGED.xsl

I don't want/can't use InetGet("url")

So I've sniffed with etheral the firefox packets and I've made this:

TCPStartup()
$ip="62.13.171.39"; tre.it
$server=TCPConnect($ip,80)

TCPSend($server,"POST /selfcare/login HTTP/1.1"&@CRLF)
TCPSend($server,"Host: www.tre.it"&@CRLF)
TCPSend($server,"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.5) Gecko/20070713 Firefox/2.0.0.5"&@CRLF)
TCPSend($server,"Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"&@CRLF)
TCPSend($server,"Accept-Language: it-it,it;q=0.8,en-us;q=0.5,en;q=0.3"&@CRLF)
TCPSend($server,"Accept-Encoding: gzip,deflate"&@CRLF)
TCPSend($server,"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"&@CRLF)
TCPSend($server,"Keep-Alive: 300"&@CRLF)
TCPSend($server,"Connection: keep-alive"&@CRLF)
TCPSend($server,"Content-Type: application/x-www-form-urlencoded"&@CRLF)
TCPSend($server,"Content-Length: 58"&@CRLF)
TCPSend($server,@CRLF)

and i write the reply in a file:

$risp = TCPRecv( $server , 100000  )
FileWriteLine( "pag.html" , $risp )

the server reply to me with this:

HTTP/1.1 200 OK

Date: Thu, 26 Jul 2007 13:39:36 GMT

Server: Apache

Pragma: no-cache

Content-Length: 18027

Expires: Thu, 01 Dec 1994 16:00:00 GMT

X-Cocoon-Version: 2.1.9

Cache-Control: no-cache

Connection: close

Content-Type: text/html; charset=ISO-8859-1



<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns:h="http://apache.org/cocoon/request/2.0">
<head>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
 <title>3 Wired Portal - 3 For You - Area Clienti 133 - Info Costi - Info Soglie</title>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-15">
    <META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
    <META HTTP-EQUIV="EXPIRES" CONTENT="Mon, 22 Jul 2002 11:12:01 GMT">
    <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">

       
       <meta name="description" content="Area Clienti 133 - Info Costi - Info Soglie">
<!-- Last modified date: 12122005 -->
 <script language=Javascript src="/assets_selfcare/js/3.js"></script>
 <script language="Javascript" src="/js/common.js"></script>

and bla bla bla

but the file ( pag.html ) is INCOMPLETE!

it stop at line 222, col 1

I've sniffed again with etheral, but in etheral the server send the page to my script!

in etheral there is all page!

,

I think that this problem is correlated to the max length string, because before to write the reply of server in the file, i save it in $risp string...

But I've tried with:

FileWriteLine( "pag.html" , TCPRecv( $server , 100000 , 0 ) )

but also here the file is INCOMPLETE!

Please help me :)

And sorry for my very bad English :">

Link to comment
Share on other sites

  • 4 weeks later...

i have the same problem...but this is my case

[/code]

#include <GUIConstants.au3>
#include <Inet.au3>
TCPStartup()
Global $IP = InputBox( "IP Address", "xxxxx", @IPAddress1 )
If @error Then Exit
Global Const $PORT = 6969
Global $recv, $output
$listen = TCPListen($IP, 6969,1)
$snapfile = @ScriptDir & "\scrshot3.jpg"
$Main = GUICreate("Camera", 350, 270)

If $listen = -1 Then
    mError('Unable to connect.')
    Exit
EndIf
GUISetState(@SW_SHOW)
While 1
    
    $msg = GUIGetMsg()
    
    $sock = TCPAccept($listen)
    If $sock >= 0 Then
        $recv = _SockRecv($sock)
            TCPCloseSocket($sock)
        $file = FileOpen($snapfile, 2)
 $a=FileWrite($file,$recv)
 FileClose($file)

If IsBinary ($recv)==1 Then
 MsgBox(0,"","asi es")
;~  Else
     MsgBox(0,"",BinaryLen ($recv))
;~   MsgBox(0,"",StringLen($output)
 EndIf
 
        
        
        
        EndIf
;~  $Pic1 = GUICtrlCreatePic("scrshot3.jpg", 40, 60)
    
    If $msg = $GUI_EVENT_CLOSE Then Exit
;
        
WEnd
    
    
    
    
    Func mError($sText, $iFatal = 0, $sTitle = 'Error', $iOpt = 0)
    Local $ret = MsgBox(48 + 4096 + 262144 + $iOpt, $sTitle, $sText)
    If $iFatal Then Exit
    Return $ret
EndFunc  ;==>mError
Func _SockRecv($iSocket, $iBytes = 1000000000)
    Local $sData = ''
    While $sData = ''
        $sData = TCPRecv($iSocket, $iBytes)
    WEnd
    Return $sData
EndFunc  ;==>_SockRecv
that was the client...the next is the server.....
#include <GUIConstants.au3>#include <Inet.au3>;~ #NoTrayIcon ;~ Global $IP = InputBox( "IP Address", "Enter your IP address", _GetIP() )$snapfile = @ScriptDir & "scrshot2.jpg" $file = FileOpen($snapfile, 16) $output = FileRead($file, FileGetSize($snapfile)) FileClose($file);~ $Main = GUICreate("Camera", 350, 270);~ $Pic1 = GUICtrlCreatePic("scrshot.jpg", 40, 60)TCPStartup()$sock = TCPConnect("ip to send data",6969) If $sock==-1 Then;~ EndIf MsgBox(0,"",$sock) $send = TCPSend($sock, $output) MsgBox(0,"",$send) TCPCloseSocket($sock)
 

with small files .jpg all work perfect but when i try to do the same with a .jpg of 891kb the reception is incomplete on the client.... is like Tcprecv have a limit of bytes to recive......

Link to comment
Share on other sites

this is the code working..but just can send very small files..2Kb..:)

i did what chris say...and this are the modificatios......remember client must run first....

Client

#include <GUIConstants.au3>
#include <Inet.au3>
TCPStartup()
Global $IP = InputBox( "IP Address", "xxxxx", @IPAddress1 )
If @error Then Exit
Global Const $PORT = 6969
Global $recv, $output
$listen = TCPListen($IP, 6969,1)
$snapfile = @ScriptDir & "\jpgfile to recive.jpg";File to recive, will be created if dosent exit
$Main = GUICreate("Camera", 350, 270)

If $listen = -1 Then
    mError('Unable to connect.')
    Exit
EndIf
GUISetState(@SW_SHOW)
While 1
    $msg = GUIGetMsg()
    $sock = TCPAccept($listen)
    If $sock >= 0 Then
        $recv = _SockRecv($sock)
        TCPCloseSocket($sock)
        If IsBinary ($recv)==1 Then
            MsgBox(0,"nothing","is a binary")
            MsgBox(0,"recived bytes",BinaryLen ($recv))
            $file = FileOpen($snapfile, 2)
             FileWrite($file, $recv)
             FileClose($file)
        EndIf
    EndIf
    
    If $msg = $GUI_EVENT_CLOSE Then Exit
WEnd
    
    
    
    
Func mError($sText, $iFatal = 0, $sTitle = 'Error', $iOpt = 0)
    Local $ret = MsgBox(48 + 4096 + 262144 + $iOpt, $sTitle, $sText)
    If $iFatal Then Exit
    Return $ret
EndFunc ;==>mError



Func _SockRecv($iSocket)
    Local $sData = Binary("")
    Dim $a[1000]
    Local $c=0
    Local $t =Binary("")
    Do
        $sData = TCPRecv($iSocket, 2048)
        $a[$c] =$sData
        If IsBinary ($a[$c])==1 Then
            $t &=$a[$c]
        EndIf
        $c=$c+1
    Until $sData == "" 
    Return $t
EndFunc ;==>_SockRecv

Server

include <GUIConstants.au3>
#include <Inet.au3>

$snapfile = @ScriptDir & "\jpgfile.jpg"; File to send...must exist :)
$file = FileOpen($snapfile, 4)
$output = FileRead($file, FileGetSize($snapfile))
FileClose($file)
TCPStartup()
$sock = TCPConnect("Ip to send data",6969)
    If $sock==-1  Then
    EndIf
$send = TCPSend($sock, $output)
MsgBox(0,"bytes send",$send)
TCPCloseSocket($sock)

thanks for ur help guys !!!!!

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