Hi,
How can I use callback and userdata with ReceiveData(1, #RECEIVEALL,..)?
An example would be nice.
Greetings, Michael
ReceiveData callback and userdata
ReceiveData callback and userdata
PostgreSQL-Library V1.0 Final: https://forum.amiga-resistance.info/vie ... =38&t=3591
Re: ReceiveData callback and userdata
Quick support here!
PostgreSQL-Library V1.0 Final: https://forum.amiga-resistance.info/vie ... =38&t=3591
-
- Posts: 267
- Joined: Fri Feb 24, 2012 9:34 am
Re: ReceiveData callback and userdata
here you have a client and a server example
Server:
CreateServer(1,2900)
conexions=0
Function p_ConnectFunc(msg)
Switch(msg.action)
Case "OnDisconnect":
closeconnection(msg.id)
conexions=conexions-1
Case "OnConnect":
conexions=conexions+1
conexioentrant=msg.clientid
Case "OnReceiveData":
data$ = ReceiveData(msg.id, #RECEIVELINE)
senddata(msg.id,data$)
EndSwitch
EndFunction
InstallEventHandler({OnConnect = p_ConnectFunc,OnDisconnect = p_ConnectFunc, onreceivedata=p_connectfunc})
BeginDoubleBuffer()
repeat
cls
checkevent
locate(0,0)
print("conexions:",conexions)
IF CONEXIONS>0 THEN senddata(CONEXIOENTRANT,"PP")
Flip()
forever
and here is the client:
serv$="192.169.1.123"
port=2550
OpenConnection(a, serv$,2900)
nprint("leftmouse to start")
WaitLeftMouse()
while(0=0)
senddata(1,"pp")
wend
Server:
CreateServer(1,2900)
conexions=0
Function p_ConnectFunc(msg)
Switch(msg.action)
Case "OnDisconnect":
closeconnection(msg.id)
conexions=conexions-1
Case "OnConnect":
conexions=conexions+1
conexioentrant=msg.clientid
Case "OnReceiveData":
data$ = ReceiveData(msg.id, #RECEIVELINE)
senddata(msg.id,data$)
EndSwitch
EndFunction
InstallEventHandler({OnConnect = p_ConnectFunc,OnDisconnect = p_ConnectFunc, onreceivedata=p_connectfunc})
BeginDoubleBuffer()
repeat
cls
checkevent
locate(0,0)
print("conexions:",conexions)
IF CONEXIONS>0 THEN senddata(CONEXIOENTRANT,"PP")
Flip()
forever
and here is the client:
serv$="192.169.1.123"
port=2550
OpenConnection(a, serv$,2900)
nprint("leftmouse to start")
WaitLeftMouse()
while(0=0)
senddata(1,"pp")
wend
- airsoftsoftwair
- Posts: 5446
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: ReceiveData callback and userdata
Probably too easy a question for the folks on here because it's pretty much all said in the documentation Well, just do something like this:
This code will receive all data until the sender closes its connection. The callback will print how many bytes it has just received and the total byte count. It will also print "Hello msu!" because that is the userdata. Note that ReceiveData()'s syntax is different for other types than #RECEIVEALL. But it's all in the documentation... which will also be available in German really soon
Code: Select all
Function p_DumpFunc(msg)
DebugPrint(msg.count, msg.total, msg.userdata)
Return(False)
EndFunction
ReceiveData(1, #RECEIVEALL, True, p_DumpFunc, "Hello msu!")