Page 1 of 1

onrecievedata Event handler

Posted: Sat Aug 16, 2014 9:30 pm
by JurassicC
The documentation says
OnReceiveData:
When you receive this message it means that there is new data available in
the connection specified by "ID", and that you should call ReceiveData()
now to read this data from the network buffer. (V5.0)
However I'm struggling with ReceiveData and the EventHandler.
If I have the ReceiveData() call in the onconnect event I can read data coming in on the server port.
However, I would like the ReceiveData() call in the OnReceiveData event. But it gives me an error that CLIENTID table is not defined.
If I change router$,count,done = ReceiveData(msg.CLIENTID, #RECEIVEALL) to router$ = ReceiveData(1, #RECEIVEALL)
It tells me server 1 is invalid.

Any pointers would be appreciated.

Here is a cut down snippet

Code: Select all

CreateServer(1,10060)

Function p_ConnectFunc(msg)
	Switch(msg.action)
	Case "OnConnect":
		
		DebugPrint("Connection Established ",msg.CLIENTID)
		;router$,count,done  = ReceiveData(msg.CLIENTID, #RECEIVEALL)
		;DebugPrint(router$)

	EndSwitch
EndFunction

Function p_ReceiveFunc(msg)
	Switch(msg.action)
	Case "OnReceiveData":
		
                DebugPrint("Receive Data ")
		router$,count,done  = ReceiveData(msg.CLIENTID, #RECEIVEALL)
		DebugPrint (router$)

	EndSwitch
EndFunction

InstallEventHandler({OnConnect = p_ConnectFunc, OnReceiveData = p_ReceiveFunc})

Repeat
	WaitEvent
Forever

CloseServer(1)
                   


Re: onrecievedata Event handler

Posted: Sat Aug 16, 2014 9:45 pm
by PEB
Try using "msg.ID" instead of "msg.CLIENTID"
(I haven't tested it to see if it works; but that is what the documentation for InstallEventHandler() says to use.)

Re: onrecievedata Event handler

Posted: Mon Aug 18, 2014 5:43 pm
by JurassicC
Thanks peb for the suggestion. It doesn't work for me if I use 1 (server ID) or msg.ID