Example #1
0
    def run(self):
        send_one_message(self.serversocket, "Hello qgis")
        while True:
            try:
                readyread, _, _ = select.select([self.serversocket,],[], [],2)
                for client in readyread:
                    recieved = recv_one_message(client)
                    if recieved:
                        data = json.loads(recieved)
                        self.message.emit(data)

            except socket.error, msg:
                print "Socket error! %s" % msg
                break
Example #2
0
print("Waiting for connection from client...")
client, addr = socket.accept()

print("Got connection to {}".format(client))

# Got a hello world
recieved = recv_one_message(client)
if recieved == "Hello qgis":
    print("Got hello message {}".format(recieved))
    print("Sending some commands now..")

    data = dict(command="new-layer",
                name="my layer",
                type="Point?crs=epsg:4326"
                )
    send_one_message(client, data)

    time.sleep(1.2)
    data = dict(command="other")
    send_one_message(client, data)

    time.sleep(1.2)
    data = dict(command="new-layer",
                name="my layer 2",
                type="Linestring?crs=epsg:4326"
    )
    send_one_message(client, data)

try:
    socket.shutdown(socket.SHUT_RDWR)
except: