Jump to content

TCP Help? Receiving bulk of Tcprecv instead of single sends. Program talking to another locally via TCP. Pseudo-Code


CrewXp
 Share

Recommended Posts

I'm not sure what's wrong. If I create 2 blank scripts, one a TCP Server and one a TCP Client, it sends just fine.

But when I incorporate tcp methods into my program, my client only receives 'blocks' of tcp messages.

Basically.. it works like this. (Pseudo Code.. not working code)

TCP Server (Downloader)-Big Program

-----------------------------------

TcpStartup()
$webserver=Opens a TCP Connection to a website on port 80, asks for binary file (TCPConnect)
$otherProgram=Opens a TCP Connection to my local TCP Server on port 127.0.0.1
$totalsize=File Size of webserver's binary file
while tcp_connection_active=1
 $recv=TcpRecv($webserver,2048) ;Gets 2048 bytes of binary code from website
$totalbytesgot=$totalbytesgot+Bytesof(recv)
write to file
tcpSEND($otherProgram,$totalBytesGot&"\"&$totalsize)
wend

TCP Client (Received Downloader progress) (Exact Code. Used for debugging)

-----------------

#include <TCP.au3> ;Uses Event Driven TCP UDF on these forums

$hSocket=_TCP_Client_Create("127.0.0.1",41909)
 _TCP_RegisterEvent($hSocket, $TCP_RECEIVE, 'Received')
 
Func Received($hSocket,$sReceived,$iError)
    ;Msgbox(0,"",$sReceived)
    msgbox(0,"",$sReceived)
EndFunc

While 1
    Sleep(100)
WEnd

Well when I run this, it seems like my Downloader is sending big BLOCKS of info to my server instead of just the small line I want (file_size_downloaded/total_file_size).

Does it have something to do with two TCP Connections active? Or maybe its because the Downloader is sending the data too fast, so it piles up on the client?

When I tried doing the TCP Client's test code, I tried doing it manually instead of the TCP.au3, it seems like if I set TCPRecv($socket,THIS) smaller and smaller, it received smaller blocks of code.

Anyways, Any suggestions. I know this sounds complicated. Maybe I can clean up my Downloader and post code later. Just wanted to see if you guys had any ideas.

--------------------------------------------------------------------------------

Posted Image

Example of what shows up: Only need "10/100" to show up in a msgbox, not "10/10010/10010/10010/10010/10010/10010/10010/10010/10010/100"

Edited by CrewXp
Link to comment
Share on other sites

Edit: I THINK it has something to do with my Downloader sending the TCP info too fast. When I put in a sleep(1000) in the while loop of the downloader, it works FINE! Is there a work-around? Obviously I can't make a download program pause for a second. It'd take forever to download!

And I know I can fix it by making TCPRecv($socket,THIS) to the EXACT number that the Downloader sends, so it knows to cut off when its supposed to, but it changes every while loop.

Any suggestions?

Link to comment
Share on other sites

you must implement a fixed length header in your script which should tell you what length the full packet has i don't think there's any other way...

the attachment is exactly that but keep in mind that this one buffers the incomming data untill the full packet is recv'ed so it's not very good for very large files...(for me it worked for a max of 100 mb)

tcpEx.au3

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

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