Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. import sys
  2. from PyQt5.QtWidgets import *
  3. from PyQt5.QtCore import *
  4. from socket import *
  5. import time
  6.  
  7. class Socket(QThread):
  8. def __init__(self, parent=None):
  9. super().__init__()
  10. self.i = 1
  11.  
  12. def run(self):
  13. while True:
  14. global c
  15. try:
  16. c = socket(AF_INET, SOCK_STREAM)
  17. c.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
  18. c.connect(('192.168.0.57', 8080))
  19. break
  20. except:
  21. print('Reconnetion... #', self.i)
  22. time.sleep(1)
  23. self.i = self.i + 1
  24. print('test')
  25.  
  26. class MyWidget(QWidget):
  27. def __init__(self):
  28. super().__init__()
  29. self.setupUI()
  30.  
  31. def setupUI(self):
  32. self.setGeometry(800, 200, 300, 300)
  33.  
  34. self.label = QLabel()
  35.  
  36. layout = QVBoxLayout()
  37. layout.addWidget(self.label)
  38.  
  39. self.setLayout(layout)
  40.  
  41. self.socket = Socket()
  42. self.socket.start()
  43. '''
  44. class MyMainWindow(QMainWindow):
  45.  
  46. def __init__(self):
  47. super().__init__()
  48. wg = MyWidget()
  49. self.setCentralWidget(wg)
  50. self.show()
  51. '''
  52. if __name__ == "__main__":
  53. app = QApplication(sys.argv)
  54. mywindow = MyWidget()
  55. mywindow.show()
  56. app.exec_()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement