Skip to content
simple_client.py 786 B
Newer Older
Antoine Millet's avatar
Antoine Millet committed
#!/usr/bin/env python
#coding:utf8

from rpc.client import SimpleRpcClient
from rpc.utils import ConnectionProxy
import socket
import threading

# Initialization of the client socket:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.connect(('127.0.0.1', 1234))

# Create the client objet binded on the socket we create above:
client = SimpleRpcClient(sock)

# Launch the event loop in separated thread:
threading.Thread(target=client.run).start()

# Create the proxy object that allow us to call easily methods on the server:
proxy = ConnectionProxy(client)

print '42 + 42 = ', proxy.add(42, 42)

# You can start this script with -i argument of the python interpreter to call
# methods with proxy interactively.