# -*- coding: UTF-8 -*-
import sys
import socket
import time
import threading
import select

HOST = '192.168.11.98'
PORT = int(sys.argv[1])

queue = []
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
queue.append(s)
print("add client to queue")



def socketRecv():
    while True:
        data = s.recv(1024).decode("utf-8")
        print(data)
        time.sleep(0.1)


def inputJob():
    while True:
        data = input()
        s.send(bytes(data, "utf-8"))
        time.sleep(0.1)


socketThread = threading.Thread(target=socketRecv)
socketThread.start()
# inputThread = Thread(target=inputJob)
# inputThread.start()
try:
    while True:
        data = input()
        s.send(bytes(data, "utf-8"))
        time.sleep(0.1)
except KeyboardInterrupt or EOFError:
    print("in except")
    # s.close()  # 關閉連線
    socketThread.do_run = False
    # socketThread.join()
    # inputThread.join()
    print("close thread")
    sys.exit(0)

[((12, 4, 12, 53), 'socket.socket', 'socket.socket', ({(12, 18, 12, 32): 'socket.AF_INET', (12, 34, 12, 52): 'socket.SOCK_STREAM'}, {}), '(socket.AF_INET, socket.SOCK_STREAM)', False, 'import socket\n'), ((33, 15, 33, 50), 'threading.Thread', 'threading.Thread', (), '', False, 'import threading\n'), ((23, 8, 23, 23), 'time.sleep', 'time.sleep', ({(23, 19, 23, 22): '(0.1)'}, {}), '(0.1)', False, 'import time\n'), ((30, 8, 30, 23), 'time.sleep', 'time.sleep', ({(30, 19, 30, 22): '(0.1)'}, {}), '(0.1)', False, 'import time\n'), ((41, 8, 41, 23), 'time.sleep', 'time.sleep', ({(41, 19, 41, 22): '(0.1)'}, {}), '(0.1)', False, 'import time\n'), ((49, 4, 49, 15), 'sys.exit', 'sys.exit', ({(49, 13, 49, 14): '(0)'}, {}), '(0)', False, 'import sys\n')]