uaveiro-leci/1ano/2semestre/labi/tema03/src/tcp_client.py

20 lines
417 B
Python
Raw Normal View History

2023-03-24 18:46:20 +00:00
import socket
def main(args=None):
tcp_s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcp_s.connect(('localhost', 1234))
while True:
str_data = input("$ ")
if not str_data or str_data == "stop":
break
tcp_s.send(str_data.encode("utf-8"))
b_data = tcp_s.recv(4096)
print("-> " + b_data.decode("utf-8"))
if __name__ == '__main__':
main()