help deal with aiomas rpc

21 views
Skip to first unread message

velop...@gmail.com

unread,
Feb 19, 2018, 8:31:39 AM2/19/18
to python-tulip
good afternoon.
I can not understand how to call the rpc method via the pure tcp

This simple server:

import aiomas

class Server:
    router = aiomas.rpc.Service()

    @aiomas.expose
    def ping(self, i):
        print('Ping receive data: {}'.format(i))
        return i


if __name__ == '__main__':
    server = aiomas.run(aiomas.rpc.start_server(
        ('127.0.0.1', 5000),
       
Server())
    )
    print('Server run')
    aiomas.run(server.wait_closed())


And this my problem tcp client

import socket
import pickle


MESS
= ['ping', [1]]

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1', 5000))
s.settimeout(1.5)
s.send(pickle.dumps(MESS))
data = s.recv(1024)
s.close()


Tell me please what's wrong. It is necessary to understand in order to realize this in other languages.Much grateful for any hint

Stefan Scherfke

unread,
Feb 20, 2018, 1:51:52 AM2/20/18
to velop...@gmail.com, python-tulip

velop...@gmail.com

unread,
Feb 20, 2018, 6:21:46 AM2/20/18
to python-tulip
Many thanks for the answer. I read the documentation several times, But I did not understand how to compose the header of the package. As a result, I figured out that the last byte is the length of the package. Everything worked

Stefan Scherfke

unread,
Feb 20, 2018, 7:11:39 AM2/20/18
to velop...@gmail.com, python-tulip
Am 2018-02-20 um 12:21 schrieb velop...@gmail.com:
>
> Many thanks for the answer. I read the documentation several times, But I did not understand how to compose the header of the package. As a result, I figured out that the last byte is the length of the package. Everything worked

The header consists of *all four* bytes. Using only the last byte only works for very short messages.

In Python, I’m using a struct to create the header from the actual
message length:

Header = struct.Struct('!L') # ! = big-endian, L = unsigned long
header_bytes = Header.pack(msg_len)

https://gitlab.com/sscherfke/aiomas/blob/master/src/aiomas/channel.py#L205
https://docs.python.org/3/library/struct.html

velop...@gmail.com

unread,
Feb 20, 2018, 9:57:36 AM2/20/18
to python-tulip
Many thanks for the answer, and for the work.)
Reply all
Reply to author
Forward
0 new messages