fork download
  1. #!/usr/bin/env python
  2. # -*- coding: utf8 -*-
  3.  
  4. import socket
  5. import threading
  6. import pickle
  7. import sys
  8. from pygame import mixer
  9. from datetime import datetime
  10.  
  11.  
  12. class Client():
  13.  
  14. def __init__(self):
  15.  
  16. self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  17. self.sock.connect(('192.168.1.40', 9090)) #192.168.1.40
  18.  
  19. msg_recv = threading.Thread(target=self.msg_recv)
  20.  
  21. msg_recv.daemon = True
  22. msg_recv.start()
  23.  
  24. while True:
  25. msg = input()
  26. if msg != 'qq':
  27. self.send_msg(msg)
  28. else:
  29. self.sock.close()
  30. sys.exit()
  31.  
  32. def msg_recv(self):
  33. while True:
  34. try:
  35. data = self.sock.recv(1024)
  36. if data:
  37. #Звуковое оповещение
  38. '''
  39. mixer.init()
  40. mixer.music.load("1.mp3")
  41. mixer.music.play()
  42.  
  43. playing = 1
  44. while playing:
  45. if not mixer.get_busy():
  46. playing = 0
  47. '''
  48. #self.now = datetime.now()
  49.  
  50. #print(socket.gethostname() + ' > ' + pickle.loads(data))
  51.  
  52. #print(datetime.strftime(datetime.now(), "%H:%M") + ' ' + socket.gethostname() + ' > ' + pickle.loads(data))
  53. print(datetime.strftime(datetime.now(), "%H:%M") + ' ' + socket.gethostname() + ' > ' + data.decode())
  54. except:
  55. pass
  56.  
  57. def send_msg(self, msg):
  58. #self.sock.send(pickle.dumps(msg))
  59. self.sock.send(msg.encode())
  60.  
  61. c = Client()
  62.  
Runtime error #stdin #stdout #stderr 0.02s 119552KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 8, in <module>
    from pygame import mixer
ImportError: No module named pygame