tcp-socket-client.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import socket
  4. HOST = '192.168.50.188'
  5. PORT = 1881
  6. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  7. s.connect((HOST, PORT))
  8. while True:
  9. indata = s.recv(1024)
  10. if len(indata) == 0: # connection closed
  11. s.close()
  12. print('server closed connection.')
  13. break
  14. print('recv: ' + indata.decode())
  15. # if indata.decode() == 'FI_Waitting':
  16. # print('FI_Waitting')
  17. # outdata = input('please input message: ')
  18. #outdata = [0xff,0x01,0x22,0x53]
  19. # print('send: ' + str(outdata))
  20. # s.send(str(outdata).encode())
  21. #if indata.decode() == 'FI_Fermentation':
  22. # print('FI_Fermentation')
  23. # outdata = input('please input message: ')
  24. #outdata = [0xff,0x01,0x22,0x53]
  25. # print('send: ' + str(outdata))
  26. # s.send(str(outdata).encode())
  27. #if indata.decode() == 'FI_Outputtingbeans':
  28. # print('FI_Outputtingbeans')
  29. # outdata = input('please input message: ')
  30. #outdata = [0xff,0x01,0x22,0x53]
  31. # print('send: ' + str(outdata))
  32. # s.send(str(outdata).encode())