# -*- coding: utf-8 -*-  

from PyQt4.QtCore import QObject, SIGNAL
from PyQt4.QtNetwork import QTcpSocket, QHostAddress
import common
import time

class CloudsTcpClient(QObject):
    _instance = 0 
    def __init__(self):
        super(CloudsTcpClient,self).__init__()
        
        self.myTcpClient = QTcpSocket()
        self.myTcpClient.abort()
        
        self.myTcpClient.connectToHost("127.0.0.1", 6001)
        if not self.myTcpClient.waitForConnected(1000):
            print "link error"
            
#         time.sleep(4)
        self.myTcpClient.write("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
#         self.myTcpClient.write("STOP_LESSON:bi")
        
        self.connect(self.myTcpClient,SIGNAL("readyRead()"),self.readData)
        
    def readData(self):
        data = self.myTcpClient.readAll()
        print data
    
    
from PyQt4.QtGui import QApplication
import sys
if __name__ == "__main__":
    app = QApplication(sys.argv)
#     time.sleep(4)
    window = CloudsTcpClient()
    app.exec_()
    
    
    
    