コード例 #1
0
ファイル: yarpread.py プロジェクト: robotology/yarp
# Copyright (C) 2006-2019 Istituto Italiano di Tecnologia (IIT)
# Copyright (C) 2006-2010 RobotCub Consortium
# All rights reserved.
#
# This software may be modified and distributed under the terms of the
# BSD-3-Clause license. See the accompanying LICENSE file for details.

import socket, re, sys

if len(sys.argv)!=2:
    print 'Call as:\n  %s /port/to/read/from'%sys.argv[0]
    exit(1)

try:
    import find_name_server
    name_server = find_name_server.find_name_server()
    print "Nameserver is here:", name_server
except:
    name_server = ('localhost',10000)
    print "Assuming nameserver is here:", name_server

def get_text(sock): # get a single line of text from a socket
    result = ""
    while result.find('\n')==-1:
        result = result + sock.recv(1024)
    result = re.sub('[\r\n].*','',result)
    return result
def get_address(s): # extract address from a name server response
    m = re.match("registration name [^ ]+ ip ([^ ]+) port ([0-9]+) type tcp",s)
    return (m.group(1),int(m.group(2))) if m else None
def send_message(addr,message): # send a message and expect a reply
コード例 #2
0
ファイル: yarpread.py プロジェクト: ste93/yarp
#!/usr/bin/python

# SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
# SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
# SPDX-License-Identifier: BSD-3-Clause

import socket, re, sys

if len(sys.argv) != 2:
    print 'Call as:\n  %s /port/to/read/from' % sys.argv[0]
    exit(1)

try:
    import find_name_server
    name_server = find_name_server.find_name_server()
    print "Nameserver is here:", name_server
except:
    name_server = ('localhost', 10000)
    print "Assuming nameserver is here:", name_server


def get_text(sock):  # get a single line of text from a socket
    result = ""
    while result.find('\n') == -1:
        result = result + sock.recv(1024)
    result = re.sub('[\r\n].*', '', result)
    return result


def get_address(s):  # extract address from a name server response
    m = re.match("registration name [^ ]+ ip ([^ ]+) port ([0-9]+) type tcp",