Page 1 of 1
Client/Server help!
Posted: Sat Jan 23, 2016 6:53 pm
by divsalv
Hi, I would need a major help ..
I would like to understand how to create a client / server.
I can not figure out how to make sure that the client receives messages from the server.
I hope someone can help me, thanks ..
Re: Client/Server help!
Posted: Sat Jan 23, 2016 9:13 pm
by PEB
1. Check out the documentation for
CreateServer().
2. Use
InstallEventHandler() to catch connections and messages from the client.
3. Use something like
DebugPrint() to show you what is happening.
Re: Client/Server help!
Posted: Sat Jan 23, 2016 11:09 pm
by divsalv
i have a problem for send data from server to client
Re: Client/Server help!
Posted: Mon Jan 25, 2016 11:00 pm
by PEB
SendData() doesn't work for you?
What does your code look like?
Re: Client/Server help!
Posted: Thu May 26, 2016 12:48 am
by divsalv
Server
Code: Select all
@DISPLAY {title="Server"}
CreateServer(1,2550)
Function p_ConnectFunc(msg)
Switch(msg.action)
Case "OnConnect":
NPrint("Connected client id", GetLocalIP(msg.clientid))
SendData(msg.clientid,"a te")
cliid=msg.clientid
Case "OnReceiveData":
/*data$ = ReceiveData(cliid, #RECEIVELINE)
NPrint(data$)*/
SendData(msg.id,"a te")
EndSwitch
EndFunction
InstallEventHandler({OnConnect = p_ConnectFunc, onreceivedata=p_connectfunc})
Repeat
CheckEvent
Wait(1)
Forever
Client
Code: Select all
@DISPLAY {title="Client"}
OpenConnection(1, "192.168.1.104", 2550)
SendData(1, "Ciao")
Function p_ConnectFunc(msg)
Switch(msg.action)
Case "OnReceiveData":
data$ = ReceiveData(msg.id, #RECEIVELINE)
NPrint(data$)
EndSwitch
EndFunction
InstallEventHandler({OnReceiveData = p_ConnectFunc})
;CloseConnection(1)
Repeat
CheckEvent
Forever
My problem is that after starting the server, running the client, is displayed the correct connection, but in the client window is no option displays the text sent by the server, but if I close the server window, appears the text sent by the server before closed.
I would like to realize a constant connection to receive and send data between client and server at all times.
How can I fix?
Re: Client/Server help!
Posted: Fri May 27, 2016 12:44 am
by PEB
You should put a carriage return ("\r") and a newline character ("\n") at the end of your send line, so the client can tell that the server's message is complete.
So if you try this. . .
SendData(msg.clientid,"a te\r\n")
. . . you will probably notice that the client recognizes the message from the server much quicker.
Re: Client/Server help!
Posted: Fri May 27, 2016 2:40 am
by divsalv
Thank you so much, I solved now.
