why does this fail?

Blitz3D Forums/Blitz3D Beginners Area/why does this fail?

Gauge(Posted 2016) [#1]
I cannot remember how to do code blocks. But i tried to do this multiple ways. After and If statement, or in a subfunction the writeline stream, chr$(13) does not work. This sends a blank line to a text base mud that I play that uses ansi. And i cannot seem to figure it out. Any suggestions. The one that its set for under the comment works and repeatedly hits enter at the menu. the one in the if then fails.

Graphics3D 800,600,16,2
Global stream
Global msg$

Print "Test server starting up...."
;Stream=OpenTCPStream("10.0.0.2",4000)
stream=OpenTCPStream("dsl-mud.org",4000)

If stream Then
Print "*Connected*"
Else
Print "failed to connect..."
EndIf

Print "running

WriteLine stream,"no"
p.player=New player
p\stream=stream



WriteLine STREAM, Chr$(13)
While Not KeyHit(1)
For p.player = Each player

If ReadAvail(p\stream) Then
;While ReadAvail(STREAM)
Print "reading"
msg$=ReadLine(p\stream)
Print msg$
;n=ReadByte(stream)
;Print Chr$(n)
;Print n
;WaitKey()
;Wend
EndIf
;this one works.....

WriteLine p\stream, Chr$(13)

If KeyHit(57) Then
;;;none of the next 3 work at all
WriteLine p\stream,Chr$(13)
;writeline stream, chr$(13)
;writeline p\stream, ""
Print "writing"
EndIf

Next


Wend


End

Type player
Field stream
End Type


jfk EO-11110(Posted 2016) [#2]
writeline stream, chr$(13) writes two empty lines. Instead writeline stream,"" writes just one linebreak, which may or may not be understood as a linefeed by the server. I think http protocol servers expect chrs 10 as linebreaks, no?


Gauge(Posted 2016) [#3]
Ahh that could help. However the qriteline in the while/loop works fine.
But the writeline in the if/then fails. Also it will not work in a function either. Anyway I try it.


Matty(Posted 2016) [#4]
You would be better using writebyte if you just want to send a single byte as writeline terminates the string with two bytes.


TomToad(Posted 2016) [#5]
per the Blitz3D docs on WriteLine
Each line of text is automatically terminated with an "end-of-line" mark, consisting of a Carriage Return character followed by a LineFeed character. (i.e. 0Dh, 0Ah )


So when you use WriteLine, you send your explicit Chr$(13) and B3D adds a Chr$(13)+Chr$(10). If you need to write one, and only one CHr(13), you are better off using WriteByte Stream,13 if expecting 8 bit characters or WriteShort Stream,13 if expecting 16 bit characters. (No need for the Chr$() in this instance).