예제 #1
0
    def create_client(self):
        self.domain = Domain(self.domain_type)
        self.sock = self.domain.socket(self.socket_type)
        self.set_socket_options()

        address = '%s://%s:%d' % (self.protocol, self.addr, self.port)
        self.sock.connect(address)
예제 #2
0
    def init_server(self, d_type, s_type):
        if self.socket_type is None:
            raise NanoServerException('Socket type is not specified')
        self.domain = Domain(d_type)
        self.sock = self.domain.socket(s_type)
        if self.port is not None:
            server_addr = '%s://%s:%d' % (self.protocol, self.addr, self.port)
        else:
            server_addr = '%s:///tmp/%s.ipc' % (self.protocol, self.node_name)
        self.log_msg('INIT in %s' % server_addr)

        return self.sock.bind(server_addr)
예제 #3
0
#  This code is released into a public domain
#
from __future__ import print_function
import os.path
import yaml
import json
import msgpack
from pynanomsg import Domain, AF_SP, REP, PUB, SOL_SOCKET, RCVTIMEO

CONFIG = 'config.yaml'

mtime = os.path.getmtime(CONFIG)
with open(CONFIG, 'rt') as f:
    data = yaml.load(f)

dom = Domain(AF_SP)
rsock = dom.socket(REP)
rsock.bind('ipc:///tmp/ns.sock')
rsock.setsockopt(SOL_SOCKET, RCVTIMEO, 1000)

usock = dom.socket(PUB)
usock.bind('ipc:///tmp/nsup.sock')
usock.setsockopt(SOL_SOCKET, RCVTIMEO, 1000)
print('Name service is listening at "ipc:///tmp/ns.sock"')
print('Run nanomsg/nanoconfig apps with:')
print('    NN_CONFIG_SERVICE=ipc:///tmp/ns.sock '
      'NN_CONFIG_UPDATES=ipc:///tmp/nsup.sock app ...')

while True:
    try:
        req = rsock.recv(4096)