MAV on TCP Server

Blitz3D Forums/Blitz3D Beginners Area/MAV on TCP Server

Ked(Posted 2006) [#1]
Hey people! I have a little bit of trouble on my TCP Chat program.... Here is the code:

[CODE]
Graphics 400,200,32,2
AppTitle "SERVER"

Global msg$,serv,t,name$,num_of_ppl=0,ready=False,ready2=False
Const ESC=1

Type user
Field stream
End Type

serv=CreateTCPServer(50000)
If serv=0 End

While Not KeyDown(ESC)
t=AcceptTCPStream(serv)

If t
msg$=ReadLine(t)
If msg$="[LOGIN]"
name$=ReadLine(t)
u.user=New user
u\stream=t
num_of_ppl=num_of_ppl+1
For u.user=Each user
WriteLine u\stream,"[SERVER]"
WriteLine u\stream,name$+" has logged in!!!"
WriteLine u\stream,num_of_ppl
Next
EndIf
Else

For u.user=Each user
If Not Eof(u\stream)
If ReadAvail(u\stream) Then
msg$=ReadLine(u\stream)
If msg$="[MESSAGE]"
msg$=ReadLine(u\stream)
READY=True
ElseIf msg$="[LOGOFF]"
msg$=ReadLine(u\stream)
READY2=True
EndIf
EndIf
Else
msg$=u\stream
ready2=True
EndIf

If ready=True
ready=False
For u.user=Each user
WriteLine u\stream,"[USER]"
WriteLine u\stream,msg$
Next
EndIf
If ready2=True
ready2=False
num_of_ppl=num_of_ppl-1
For u.user=Each user
WriteLine u\stream,"[SERVER]"
WriteLine u\stream,msg$+" has logged off."
WriteLine u\stream,num_of_ppl
Next
EndIf
Next
EndIf
Delay 10

Wend

msg$="The server has logged off and you have been disconnected."
For u.user=Each user
WriteLine u\stream,"[SERVER]"
WriteLine u\stream,msg$
Next
Delay 20
End
[/CODE]

I get a MAV error every time someone sends a message.
I get the area right at the end of the u.user=each user loop. It gets the error at Next. Everything I do it always
gets the error at Next.


jfk EO-11110(Posted 2006) [#2]
Did you try this in debug mode? It may give you a more detailed error message.


Ked(Posted 2006) [#3]
I did. I enabled debug mode and it said the exact same thing except it was in a slightly different window with an !. It works fine if they are entering their name. It doesn't work fine if they entered text.


b32(Posted 2006) [#4]
Maybe the text contains invalid characters (space etc.) that the names don't contain ?


Ked(Posted 2006) [#5]
I've tried everything. I even took out the []'s on the headers!


Ked(Posted 2006) [#6]
still here!


markcw(Posted 2006) [#7]
i don't know anything about tcp chat myself, but is there nothing in the archives that could help?

edit: yes, here's one.
edit2: oops, seems you know this one.

http://www.blitzbasic.com/codearcs/codearcs.php?code=28