Esempio n. 1
0
def get_radio_info():
    client = Client()
    client.connect(host, port)

    print("Sending request to server...")
    # object variables as dict
    client.send(iradio_structs.station_info_request().__dict__)
    radio_list = client.recv()
    print("radio_list recieved")

    return jsonify(**radio_list)
Esempio n. 2
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()
Esempio n. 3
0
class Auth(object):
    """Stores Customer password in safe form. I expect only 1 user/admin per script"""

    data = {}  # stores previous data from master

    def __init__(self):
        self.password = None
        try:
            self.client = Client().connect("127.0.0.1", ADMIN_PORT)
        except socket.error:
            self.client = None

    def __ask_master(self):
        req = {
            "method": "get",
            "endpoint": "info"
        }
        if self.client:
            try:
                return self.client.send(req).recv()
            except socket.error:
                return {"error": "Socket f****d up"}
        else:
            return {"error": "No connection"}

    def ask_master(self):
        self.data = self.__ask_master()
        return self.data

    def hash_data(self, data):
        new_hash = hashlib.md5()
        new_hash.update("mask-{0}-vladimir".format(data))
        return new_hash.hexdigest()

    def set_password(self, psw):
        self.password = self.hash_data(psw)

    def check(self, psw):
        return self.password == self.hash_data(psw)

    def password_is_set(self):
        return self.password is not None
Esempio n. 4
0
from jsonsocket import Client
import time
import datetime

host = "192.168.43.70"
port = 12345

#accepted_operations = [ "sensor", "webcam", "irrigate", "stop_irrigate" ] # For testing

while True:
    data = raw_input("Introduce operation and your device_id: ")
    data = data.split(" ")
    if (len(data) == 2):
        operation = data[0]
        device_id = int(data[1])
        client = Client()
        to_send = {
            "device_id": device_id,
            "operation": operation,
            "rule_id": ""
        }
        print "{0} => SND: device_id: {1} operation: {2}".format(
            datetime.datetime.now(), device_id, operation)
        client.connect(host, port).send(to_send)
        response = client.recv()
        print "{0} => RCV: {1}".format(datetime.datetime.now(), response)
        client.close()
    else:
        print(
            "Introduced invalid parameters. You should do it like this: sensor 123"
        )
Esempio n. 5
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()
Esempio n. 6
0
# then from a cli, send the commmand via 'python sendit.py <mode> <HASH> <label>' where hash is the hash on the torrent client,
# label is the label given to the hash on the client, and mode is either add or queue.

from jsonsocket import Client
import sys

host = 'localhost'
port = 50007
mode = sys.argv[1]
if mode == 'queue':
    hash = None
    label = None
else:
    hash = sys.argv[2]
    label = sys.argv[3]

data = {
    'mode': mode,
    'apikey': '#put apikeyhere',
    'hash': hash,
    'label': label
}

client = Client()
client.connect(host, port)
client.send(data)
response = client.recv()
print response
client.close()

feature_scaler = load_scaler(out_dir=OFFLOAD_DNN_MODEL_DIR)

# features the offloader NN expects as input
train_features = [
    'SVM_confidence', 'embedding_distance', 'face_confidence',
    'frame_diff_val', 'numeric_prediction', 'unknown', 'num_detect'
]
######################################

# START THE MOBILE CLIENT
#########################################
host = args['host']
port = int(args['port'])

# Client code:
client = Client()

# setup for making the output video
#########################################
frame_width = 450
frame_height = 600

prefix = args['prefix_outvideo']

# do we write an output video?
if args['out_video_write_mode'] == 'True':
    out_video_write_mode = True
else:
    out_video_write_mode = False

# do we write output files?
Esempio n. 8
0
 def __init__(self):
     self.password = None
     try:
         self.client = Client().connect("127.0.0.1", ADMIN_PORT)
     except socket.error:
         self.client = None
Esempio n. 9
0
volt = 0

try:
    while 1:

        time.sleep(1)

        ser.write('readbat\n\r')
        response = ser.readline()

        while response.find('$') == -1:
            response = ser.readline()
            print response
        if response.find('PI_SHU') != -1:
            print "sent command"
            client = Client()
            client.connect(host, port).send({'command': 1})
            client.close()
        if response.find('Battery') != -1:
            volt = response[9:-7]

        ser.write('time\n\r')
        response = ser.readline()
        while response.find('$') == -1:
            response = ser.readline()
            print response
        if response.find('PI_SHU') != -1:
            print "sent command"
            client = Client()
            client.connect(host, port).send({'command': 1})
            client.close()
Esempio n. 10
0
        #'light': light},
        'imu': {
            'orientation_rad': orient_r,
            'orientation_deg': orient_d,
            'compass': compass,
            'compass_r': compass_r,
            'gyroscope': gyro,
            'gyroscope_r': gyro_r,
            'accelerometer': accel,
            'accelerometer_raw': accel_r
        }
    }


MY_ID = ''
HOST = ''
PORT = 2320

client = Client()
client.connect(HOST, PORT)

while True:
    # Get all data
    data = get_data()
    data['pi_id'] = MY_ID

    # Send it off to the server and confirm reception
    client.send(data)
    response = client.recv()
    print(response)
Esempio n. 11
0
 #print('\tIP: ' + str(server.socket.gethostbyname(server.socket.gethostname())))
 #print('\tPORT:' + str(port))
 #print('\tSERVER: ' + str(emitterDomain))
 #server.accept()
 #data = server.recv()
 data = server.accept().recv()
 print('Msg Memory: ' + str(msgList))
 print('Socket Receive Data: ' + str(data))
 if data['act'] == 'send':
     server.send({'status': '200'})
     if data['recipientDomain'] == serverDomain:
         data['status'] = '202'
         msgList.append(data)
     if data['recipientDomain'] != serverDomain:
         print('Transferring Msg: ' + str(data['recipientDomain']))
         client = Client()
         data['status'] = '201'
         response = client.connect(
             srvlist[data['recipientDomain']]['ip'],
             srvlist[data['recipientDomain']]['port']).send(data).recv()
         client.close()
         if response['status'] == '200':
             print('Transfered Msg Success')
         else:
             print('Transfered Msg Error')
 if data['act'] == 'receive':
     requesterMsg = []
     for i in msgList:
         if i['recipientUser'] == data['requesterUser']:
             requesterMsg.append(i)
             msgList.remove(i)
Esempio n. 12
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()
Esempio n. 13
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()
Esempio n. 14
0
#!/usr/bin/env python3

from jsonsocket import Client, Server

host = 'localhost'
port = 8001

# Client code:
client = Client()
client.connect(host, port).send({'some_list': [123, 456]})
response = client.recv()
# response now is {'data': {'some_list': [123, 456]}}
client.close()




Esempio n. 15
0
from jsonsocket import Client
import time
import os

host = 'LOCALHOST'
port = 8080

time.sleep(1)

try:
    while 1:
        testVar = raw_input("Enter Command: ")
        print testVar
        client = Client()
        client.connect(host, port).send({'command': testVar})
        response = client.recv()
        print response['message']
        client.close()
except KeyboardInterrupt:
    print "bye"
Esempio n. 16
0
#-*- coding: utf8 -*-
from jsonsocket import Client
import base64

client = Client()
#client.connect('localhost', 49945).send({'some_list': [123, 456]})#, base64.encodestring('한글')]})
client.connect('localhost', 49945).send({'some_list': [123, 456, '한글']})
response = client.recv()
for k, v in response['data'].items():
  print k
  for i in v:
    print i
client.close()
Esempio n. 17
0
File: client.py Progetto: 0Kraft/EuW
#file:client.py
from jsonsocket import Client
import time

host = 'LOCALHOST'
port = 8080

i = 1
while True:
    client = Client()
    client.connect(host, port).send({'test': i})
    i += 1
    response = client.recv()
    print response
    tt = response["response"]["test"]
    print tt
    client.close()
    time.sleep(1)