Home
Products
Community
Manuals
Contact
Login or Signup

Server / Client problem

BlitzPlus Forums/BlitzPlus Programming/Server / Client problem

Filax(Posted 1+ years ago) #1
Hi :) i'm trying to make a little test client/server with blitz plus
but i have a problem :

when i'm connecting to the server, i see the "hello" message
on the serveur listbox.

but when a client disconnect and send a message to server,
but the server see nothing ???


win = CreateWindow("Test",100,100,400,450,0,57)

Global log_list=CreateListBox( 10,40,380,150,win )
Global client_list=CreateListBox( 10,230,380,200,win )

Global createserver_but=CreateButton("Server",10,10,100,20,win,1)
Global connectserver_but=CreateButton("Connect",110,10,100,20,win,1)
Global disconnect_but=CreateButton("DisConnect",210,10,100,20,win,1)

Global server=0
Global client =0

Repeat

Select WaitEvent(1)
Case $401
Select EventSource()
Case createserver_but
server = CreateTCPServer (80)

If Not server Then
AddGadgetItem client_list,"server failed ..."
Else
AddGadgetItem client_list,"server open ..."+server

EndIf
Case connectserver_but
client = OpenTCPStream( "localhost",80 )

If Not client Then
AddGadgetItem client_list,"connection failed ..."
Else
AddGadgetItem client_list,"connection open ..."

WriteString client,"Hello ..."
EndIf
Case disconnect_but
If client Then
WriteString client,"Disconnected ..."
Delay 2000
CloseTCPStream client
EndIf
End Select
Case $803
If server<>0 Then
CloseTCPServer server
EndIf

End
End Select

If server<>0 Then
strStream=AcceptTCPStream(server)

If strStream Then
If ReadAvail(strStream) Then
TMp$=ReadString(strStream)
AddGadgetItem log_list,TMp$

EndIf
EndIf
EndIf
Until KeyHit(1)


semar(Posted 1+ years ago) #2
Have a look here:
http://www.blitzbasic.com/codearcs/codearcs.php?code=28
It's Blitz2D, but the network commands are the same.

I think you should use WriteLine$ instead of WriteString, as well as ReadLine$ instead of ReadString.

Hope it helps,
Sergio.


Filax(Posted 1+ years ago) #3
Thanks Semar :)