chattle/client.py

36 lines
963 B
Python
Raw Normal View History

2021-09-30 01:21:18 +02:00
__author__ = "Kieran Osborne"
__version__ = "0.0.1"
__status__ = "Development"
if (__name__ == "__main__"):
import config
import socket
import select
import sys
2021-09-30 01:21:18 +02:00
address = (config.host, config.port)
2021-09-30 01:21:18 +02:00
print("Starting connection to", address)
2021-09-30 01:21:18 +02:00
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server_socket:
server_socket.setblocking(False)
server_socket.connect_ex(address)
2021-09-30 01:21:18 +02:00
inputs = [sys.stdin, server_socket]
2021-09-30 01:21:18 +02:00
while True:
readable_io, _, _ = select.select(inputs, [], [])
2021-09-30 01:21:18 +02:00
for io in readable_io:
if (io == server_socket):
print(io.recv(4096))
elif (io == sys.stdin):
message = sys.stdin.readline()
server_socket.send(message.encode("utf-8"))
sys.stdout.write("<You>")
sys.stdout.write(message)
sys.stdout.flush()
2021-09-30 01:21:18 +02:00