Page 1 of 2

RPC Library? help-me

Posted: Fri May 12, 2017 12:51 pm
by marcosmfilho
Good morning, I'm doing a distributed systems discipline in college ...

The first exercise was to create a multiplayer game with sockets. It was easy.

My problem is in the second exercise, I need to change the game technology to rpc (remote procedure call), something similar to the Java RMI.

Is there any library that will help me to implement rpc (in Lua)?

I'm using love2d.

Re: RPC Library? help-me

Posted: Fri May 12, 2017 1:37 pm
by zorg
RPC is a pretty generic technology though; but i'm guessing you need to have a server which gets requests to call procedures, and then return the results to the client(s)?

you can just send 1+n messages, first the function name, then the parameters that the function expects, and it will return the results to you...

though you might need to create something more specialized, you didn't specify.

Re: RPC Library? help-me

Posted: Fri May 12, 2017 1:47 pm
by marcosmfilho
zorg wrote: Fri May 12, 2017 1:37 pm RPC is a pretty generic technology though; but i'm guessing you need to have a server which gets requests to call procedures, and then return the results to the client(s)?

you can just send 1+n messages, first the function name, then the parameters that the function expects, and it will return the results to you...

though you might need to create something more specialized, you didn't specify.
That's exactly what I need. I need to move a part by calling a server's "movePiece" method for example and the piece's position is updated on all other clients. Only with remote calls, without using sockets explicitly. Something similar to JAVA RMI.

Re: RPC Library? help-me

Posted: Fri May 12, 2017 7:06 pm
by raidho36
Remote calls work over sockets. I don't know what's your problem with it.

Re: RPC Library? help-me

Posted: Sat May 13, 2017 6:28 pm
by MasterLee
The Problem is easy when communicating with other systems there should be an standard. It should be documented how to make RPC call or how to process them, so that both the client or server could be changed.
SOAP for example is an standard that could be used for that.
Luckily nobody has to learn SOAP to use it as most languages have subsystems (e.g. modules, libraries etc.) to handle all aspects off SOAP Stuff.
But visit http://ladonize.org/ there are some examples for Python, PHP and Javascript. You may also find some JSON-WSP which is an alternative to SOAP, but it maybe not supported by any Lua module.

Re: RPC Library? help-me

Posted: Sun May 14, 2017 6:22 pm
by airstruck
I took a crack at it.

https://gist.github.com/airstruck/5e0d0 ... 4afe6e75dc

Uses binser for serialization. Should be pretty straightforward, see examples. Everything is synchronous. Define your remote procs as methods of the rpc server object (as rpc:method, not rpc.function), and then call them as methods of the rpc client object. Magic!

Probably too brittle for anything serious, but should be fine for a school project.

Re: RPC Library? help-me

Posted: Sun May 21, 2017 12:56 pm
by marcosmfilho
airstruck wrote: Sun May 14, 2017 6:22 pm I took a crack at it.

https://gist.github.com/airstruck/5e0d0 ... 4afe6e75dc

Uses binser for serialization. Should be pretty straightforward, see examples. Everything is synchronous. Define your remote procs as methods of the rpc server object (as rpc:method, not rpc.function), and then call them as methods of the rpc client object. Magic!

Probably too brittle for anything serious, but should be fine for a school project.

Perfect, besides functions, can I access variables and objects remotely?

Re: RPC Library? help-me

Posted: Sun May 21, 2017 8:19 pm
by airstruck
Not directly, but you can write getter and setter RPC methods instead. This way you can make sure a client has permission to change or view data based on whatever rules you want. The only reason I went for "methods" rather than "functions" is so you have access to the relevant sockets via self (so you can determine connected client's IP, for example).

Re: RPC Library? help-me

Posted: Sun May 21, 2017 9:19 pm
by marcosmfilho
airstruck wrote: Sun May 21, 2017 8:19 pm Not directly, but you can write getter and setter RPC methods instead. This way you can make sure a client has permission to change or view data based on whatever rules you want. The only reason I went for "methods" rather than "functions" is so you have access to the relevant sockets via self (so you can determine connected client's IP, for example).
I have a problem with this rpc library that you showed me. I can not put generic ports for clients, the client port has to be the same as the server port to work, so I can not differentiate the clients.

For example, how would you do a chat using this RPC implementation between two clients and a server? (Remembering that I can not use sockets explicitly, by teacher's requirement, only remote calls, which obviously use sockets behind)

Can you help me? First of all, I want to thank you for your help.

Re: RPC Library? help-me

Posted: Sun May 21, 2017 9:47 pm
by marcosmfilho
marcosmfilho wrote: Sun May 21, 2017 9:19 pm
airstruck wrote: Sun May 21, 2017 8:19 pm Not directly, but you can write getter and setter RPC methods instead. This way you can make sure a client has permission to change or view data based on whatever rules you want. The only reason I went for "methods" rather than "functions" is so you have access to the relevant sockets via self (so you can determine connected client's IP, for example).
I have a problem with this rpc library that you showed me. I can not put generic ports for clients, the client port has to be the same as the server port to work, so I can not differentiate the clients.

For example, how would you do a chat using this RPC implementation between two clients and a server? (Remembering that I can not use sockets explicitly, by teacher's requirement, only remote calls, which obviously use sockets behind)

Can you help me? First of all, I want to thank you for your help.
For example:
In server:
function newMessage(nameuser, message)
return nameuser .. ': ' .. message
end

Client 1:
rpc:newMessage('client1', 'hello client2')

Client 2 (The message should arrive instantaneously on client 2 without it having to make any calls):

client1 says: 'hello client2'

How can I do this with RPC only? Help me out :(