chatting/client.py

50 lines
1.2 KiB
Python

import sys
from PodSixNet.Connection import connection
from PodSixNet.Connection import ConnectionListener
import time
import threading
import os
#os.system('cls' if os.name == 'nt' else 'clear')
name = input("name: ")
queue = []
recorded = []
temp = 0
class MyNetworkListener(ConnectionListener):
def __init__(self, host, port):
self.Connect((host, port))
def Network_queuesync(self, data):
global temp
temp = 0
global queue
queue = data["queue"]
connection2 = MyNetworkListener(input("host: "), int(input("port: ")))
data = {"action": "setname", "name":name}
connection2.Send(data)
def chatloop():
global connection2
global recorded
while True:
for line in sys.stdin:
os.system('cls' if os.name == 'nt' else 'clear')
for i in recorded:
print(i)
data = {"action": "send", "message": line}
connection2.Send(data)
threading.Thread(target=chatloop).start()
while True:
for i in queue:
print(i)
recorded.append(i)
queue.remove(i)
connection2.Pump()
connection.Pump()
if temp >= 100:
print("lost connection to server.")
exit()
exit()
temp += 1
time.sleep(0.001)