Пример #1
0
def send_data(data, des_ip, des_port):
    socket = None
    for i in range(0, 5):
        client_soc = Client()
        socket, success = client_soc.connect(des_ip, des_port)
        if (success):
            if socket != None:
                if (socket.send(data)):
                    client_soc.close()
                    if (i >= 1):
                        print("Data sent!!!")
                    break
        print("fail to send {} times to {}".format(i + 1, des_ip))
        client_soc.close()
Пример #2
0
# default uses python 2
import sys, os
base_video_dir = os.environ['CLOUD_ROOT_DIR']
utils_dir = base_video_dir + '/utils/'
sys.path.append(utils_dir)

from jsonsocket import Client, Server

host = 'localhost'
port = 8000

# Client code:
client = Client()
#client.connect(host, port).send({'some_list': [123, 456]})
client.connect(host, port).send([123, 456])
response = client.recv()
print('response: ', response)
# response now is {'data': {'some_list': [123, 456]}}
client.close()
Пример #3
0
#!/usr/bin/python           # This is client.py file

from jsonsocket import Client

host = '192.168.12.1' 	   
port = 7878                # Reserve a port for your service.
client = Client()
print 'Client starts.'

client.connect((host, port))
print 'Client connected.'

client.send({'tx_id': 1234, 'amount': 4321})
response = client.recv()
print response
client.close()