Repeat writeline
BlitzPlus Forums/BlitzPlus Programming/Repeat writeline
| ||
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/ |
| ||
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. |
| ||
I think the HTTP 1.1 protocol allows multiple gets during a single session. |
| ||
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. |
| ||
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 |
| ||
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? |
| ||
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. |