onrecievedata Event handler

Discuss any general programming issues here
Post Reply
User avatar
JurassicC
Posts: 36
Joined: Fri May 25, 2012 9:48 pm

onrecievedata Event handler

Post 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)
                   

AmigaOne X1000 - RadeonHD 7870, 4GB RAM - AmigaOS 4.1ß
AmigaOne X5000 - Radeon R7 250, 2GB RAM - AmigaOS 4.1ß

PEB
Posts: 523
Joined: Sun Feb 21, 2010 1:28 am

Re: onrecievedata Event handler

Post 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.)

User avatar
JurassicC
Posts: 36
Joined: Fri May 25, 2012 9:48 pm

Re: onrecievedata Event handler

Post by JurassicC »

Thanks peb for the suggestion. It doesn't work for me if I use 1 (server ID) or msg.ID
AmigaOne X1000 - RadeonHD 7870, 4GB RAM - AmigaOS 4.1ß
AmigaOne X5000 - Radeon R7 250, 2GB RAM - AmigaOS 4.1ß

Post Reply