Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

OpenERP 7.0 and NetRPC

By
Assem
on 8/28/14, 6:33 AM 988 views

Hello,

I have a php application that connect to a 6.0 version of OpenERP using netrpc. I'm now trying to check if I can use the same code to connect my application to a 7.0 version. After analysing the code, I found that it's based on socket communications, so I prepared this code to make somme tests:

import socket
import cPickle
msg = ('common', 'login', 'db_name', 'admin', 'secret')
msg = cPickle.dumps([msg,None])
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print sock.connect_ex(('localhost', 8070))
sock.sendall('%8d%s%s' % (len(msg), True and "1" or "0", msg))
#buf=''
#print sock.recv(8 - len(buf))
#print "put"


def read(socket, size):
    buf=''
    while len(buf) < size:
        print "innn"
        try:
            chunk = socket.recv(size - len(buf))
            print "cunk ", chunk
            if chunk == '':
                raise RuntimeError, "socket connection broken"
            buf += chunk
        except Exception, e:
            print e
            
    return buf

size = int(read(sock, 8))
buf = read(sock, 1)
exception = buf != '0' and buf or False
res = cPickle.loads(read(sock, size))

if isinstance(res[0],Exception):
    if exception:
        raise TinySocketError(ustr(res[0]), ustr(res[1]))
    raise res[0]
else:
    print "res ",res[0]

When I run this code whyle a 6.0 server is running, I got an answer. But with a 7.0 server running, I have a Timeout problem (and I see openerp.service.netrpc_server: starting NET-RPC service on 0.0.0.0:8070 in the log so the netrpc service must be running). So I digged a litte in the OpenERP net-rpc code, and I found that the netrpc server is runned via the netrcp_server.py. After that I discovered that the difference between 6.0 and 7.0 is that in the first one, the function TinySocketServerThread.run was called, but in the second, it wasn't, witch means (If I'm not wrong) that there was no client socket waiting for connection witch explain why I don't get an answer.

So, is there anything wrong with my analysis? Did someone tested to use net rpc with a 7.0 of openerp? Did I miss something to make the netrpc work properly?

Thanks,

Assem.

0
Assem
On 8/28/14, 10:18 AM

Well, 

After more checking I found this: in the 6.0 version, the netrpc and other service are runned by calling

netsvc.Server.startAll()

In openerp-server.py. In 7.0 version, this function is not called nowere, so I added :

netrpc_server.Server.startAll()

In the __init__.py under the service folder in the end of the start_services function : after that, the thread was lunched and I can see that the server did receive the socket call. But I found another problem: in TinySocketClientThread.run function, this line 

ts = openerp.server.netrpc_socket.mysocket(self.sock)

must be replaced by this one

ts = openerp.service.netrpc_socket.mysocket(self.sock)

After that, it worked fine. 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 8/28/14, 6:33 AM
Seen: 988 times
Last updated: 3/16/15, 8:10 AM