TCP code works in Blitz3d but fails in BlitzPlus?

BlitzPlus Forums/BlitzPlus Programming/TCP code works in Blitz3d but fails in BlitzPlus?

Darth Testine(Posted 2005) [#1]
Hi, I've done a lot of programming in Blitz3d, but I'm working with BlitzPlus pretty much for the first time.

What the hell am I doing worng??
I'm really frustrated. Please help me if you can!

When I run the updated default TCP code given in the online docs for the command OpenTCPStream, it works for Blitz3d but fails in BlitzPlus.

Here are the programs for each. They *should* only very in the output commands...

Here is the program I ran in Blitz3d:
Graphics 800,600

; OpenTCPStream/CloseTCPStream/ReadAvail Example

Print "Connecting..."
tcp=OpenTCPStream( "www.blitzbasic.com",80 )

If Not tcp Print "Failed 1.":WaitKey:End

Print "Connected! Sending request..."

WriteLine tcp,"GET http://www.blitzbasic.com HTTP/1.0"
WriteLine tcp,"HOST: www.blitzbasic.com" 
WriteLine tcp,"" 


If Eof(tcp) Print "Failed 2.":WaitKey:End

Print "Request sent! Waiting for reply..."

While Not Eof(tcp)
Print ReadLine$( tcp )
Print "Bytes available:" + ReadAvail(tcp)
Wend

If Eof(tcp)=1 Then Print "Success!" Else Print "Error!"

CloseTCPStream tcp

WaitKey


Here is the program I ran in BlitzPlus:
Global deskwidth=ClientWidth(Desktop())
Global deskheight=ClientHeight(Desktop())
Global winwidth=400
Global winheight=300
Global window=CreateWindow("test",(deskwidth-winwidth)/2,(deskheight-winheight)/2,winwidth,winheight,0,11)

Global text_display=CreateTextArea(0,25,winwidth,winheight-75,window)
	SetGadgetLayout text_display,1,1,1,1




; OpenTCPStream/CloseTCPStream/ReadAvail Example

AddTextAreaText text_display,Chr$(10)+"Connecting..."
tcp=OpenTCPStream( "www.blitzbasic.com",80 )

If Not tcp AddTextAreaText text_display,Chr$(10)+"Failed 1.":WaitKey:End

AddTextAreaText text_display,Chr$(10)+"Connected! Sending request..."

WriteLine tcp,"GET http://www.blitzbasic.com HTTP/1.0"
WriteLine tcp,"HOST: www.blitzbasic.com"
WriteLine tcp,""

If Eof(tcp) AddTextAreaText text_display,Chr$(10)+"Failed 2.":WaitKey:End

AddTextAreaText text_display,Chr$(10)+"Request sent! Waiting for reply..."

While Not Eof(tcp)
AddTextAreaText text_display,Chr$(10)+ReadLine$( tcp )
AddTextAreaText text_display,Chr$(10)+"Bytes available:" + ReadAvail(tcp)
Wend

If Eof(tcp)=1 Then AddTextAreaText text_display,Chr$(10)+"Success!" Else AddTextAreaText text_display,Chr$(10)+"Error!"

CloseTCPStream tcp

WaitKey


Blitz3d shows the HTML as it should.
BLitzPlus says "Failed 1".


ozak(Posted 2005) [#2]
You might want to simply "GET / HTTP/1.0" to get the root of
the website. Works in blitzplus for me :)

Skip the host and add Chr(10) so it becomes:
WriteLine tcp,"GET / HTTP/1.0"
WriteLine tcp,Chr(10)



Darth Testine(Posted 2005) [#3]
I'll give that a shot tonight.

But why would the same message work when I send it from Blitz3d, but not BlitzPlus?


ozak(Posted 2005) [#4]
I guess Blitz3D does some conversion converting www.blitzbasic.com to / which is the proper approach.
You don't GET the website address, but paths that originate from the root. I.e. / for too /games/index.html etc.


Darth Testine(Posted 2005) [#5]
Nope. If you note, the error happens before that line is even sent.

I stripped it down. This exact same snippet of code succeeds in Blitz3d 1.88 and fails in BlitzPlus 1.40:

tcp=OpenTCPStream("www.blitzbasic.com",80)
If Not tcp 
	output("Failed.")
Else
	output("Sucess.")
EndIf


GAHH!!!!!
Can anyone else replicate this same result or is it somehow my problem?
Should I report this as a bug?


Beaker(Posted 2005) [#6]
That code snippet does exactly the same for me in B+ and BB3D.


ozak(Posted 2005) [#7]
Me too.


Darth Testine(Posted 2005) [#8]
Wow! Thanks for the info guys!

But now I'm REALLY at a loss.
Maybe I need to reinstall B+ or something.


WolRon(Posted 2005) [#9]
Code snippet works in both for me as well.


Wings(Posted 2005) [#10]
tcp=OpenTCPStream("www.blitzbasic.com",80)
If Not tcp
output("Failed.")
Else
output("Sucess.")
EndIf


have some one installed a http server on your pC ?
cause this is why it fails.. port 80 is already taken.
try another port 1024 or above.

This cold also be your personal norton internet security that blocks your program. :)