-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
39 lines (31 loc) · 895 Bytes
/
client.py
File metadata and controls
39 lines (31 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# !/usr/bin/python3
# -*- coding: utf-8 -*-
from __future__ import print_function
import socket
import sys
import pickle
with open('ports.txt', 'r') as file:
content = file.readlines()
HOST = content[1] # Endereco IP do Servidor
PORT = int(content[0]) # Porta que o Servidor está
# Criando a conexão
tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
destino = (HOST, PORT)
tcp.connect(destino)
print('\nDigite suas mensagens')
print('Para sair use CTRL+X\n')
# Recebendo a mensagem do usuário final pelo teclado
mensagem = input()
# Enviando a mensagem para o Servidor TCP através da conexão
while mensagem != '\x18':
tcp.send(mensagem.encode())
data = tcp.recv(1024)
if not data:
break
if mensagem[0] == 'G':
print(pickle.loads(data))
else:
print(data.decode())
mensagem = input()
# Fechando o Socket
tcp.close()