Repeat writeline

BlitzPlus Forums/BlitzPlus Programming/Repeat writeline

mattm591(Posted 2005) [#1]
I need my program to constantly be talking to the server and can do this by placing "writeline" within my repeat section of the program. It is possible to get this working by having opentcpstream and closetcpstream on either side of the writeline, but this causes my program to respond very slowly. Is there a way to send muliple requests for a file to a server and just opening the tcpstream once. So for example

opentcpstream("server.com",80)
Repeat
WriteLine usercheckserver,"GET file HTTP/1.0"
WriteLine usercheckserver,"Host: server.com"
WriteLine usercheckserver,Chr$(10)
Forever

Except that doesn't work because once i've sent those lines i can't send a new request for a file. How to get round this?
Thanks/


Regular K(Posted 2005) [#2]
Some servers stop people from flooding, and well, block you from trying to get that file over and over. This may be the problem?

You never told us what the problem is, exactly.


skidracer(Posted 2005) [#3]
I think the HTTP 1.1 protocol allows multiple gets during a single session.


mattm591(Posted 2005) [#4]
Changing to 1.1 didn't help. The problem is I need to have a GET file request repeated forever within my program, but if I am constantly opening and closing TCP streams the program slows down too much. So how can I open the stream once and send the file request multiple times? Bearing in mind that each time i send the request with a different variable so basically request is

WriteLine usercheckserver,"GET file.php?"+var$+" HTTP/1.0"

var being read from a text file of multiple lines, so first time 'a' will be read second time 'b' etc.


skidracer(Posted 2005) [#5]
Did you look into what is involved with implementing 1.1 protocol? This code shows repeated GET's using a single connection working just fine:
server$="www.blitzbasic.com"

www = OpenTCPStream(server,80)
If Not www 
	Notify" connection failed"
	End
EndIf

While True

	request$="GET http://www.blitzbasic.com HTTP/1.1" + Chr$(13)+Chr$(10) + "Host: " + server$ + Chr$(13)+Chr$(10) + "User-Agent: blitzbasic" + Chr$(13)+Chr$(10) + "Accept: */*" + Chr$(13)+Chr$(10)

	WriteLine www,request

	While True
		a$=ReadLine(www)
		If Instr(Lower(a$),"</html>") Exit
		Print a$
	Wend
	
	Print ""
	Print "received document "+n+" times
	n=n+1
	Print ""

Wend



mattm591(Posted 2005) [#6]
This presents a new problem. When I switch to 1.1 it now places a number at the top and botom of the page meaning the first line read is no longer the php result. Any idea why this is and how to get rid of it?


skidracer(Posted 2005) [#7]
That's the 1.1 header which has useful fields such as Content-Length. To ignore read lines until you get a blank line, the document proper starts directly after.