Client/Server help!

Find quick help here to get you started with Hollywood
Post Reply
divsalv
Posts: 23
Joined: Sun Mar 22, 2015 3:01 am

Client/Server help!

Post 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 ..
PEB
Posts: 569
Joined: Sun Feb 21, 2010 1:28 am

Re: Client/Server help!

Post 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.
divsalv
Posts: 23
Joined: Sun Mar 22, 2015 3:01 am

Re: Client/Server help!

Post by divsalv »

i have a problem for send data from server to client
PEB
Posts: 569
Joined: Sun Feb 21, 2010 1:28 am

Re: Client/Server help!

Post by PEB »

SendData() doesn't work for you?

What does your code look like?
divsalv
Posts: 23
Joined: Sun Mar 22, 2015 3:01 am

Re: Client/Server help!

Post 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?
PEB
Posts: 569
Joined: Sun Feb 21, 2010 1:28 am

Re: Client/Server help!

Post 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.
divsalv
Posts: 23
Joined: Sun Mar 22, 2015 3:01 am

Re: Client/Server help!

Post by divsalv »

Thank you so much, I solved now. :lol:
Post Reply