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.
[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.