Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # coding: utf-8
- import socket
- def cliente():
- IP = '192.168.0.8'
- PORT = 25
- sckt = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- dest = (IP, PORT)
- sckt.connect(dest)
- msg = input("Digite a mensagem: ")
- while 1:
- msg = bytes(msg, "utf-8")
- sckt.send(msg)
- msg = input("Digite a mensagem: ")
- sckt.close()
- def servidor():
- IP = '192.168.0.8'
- PORT = 25
- sckt = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- orig = (IP, PORT)
- sckt.bind(orig)
- sckt.listen(1)
- while 1:
- con, cliente = sckt.accept()
- print("Conectado com ", cliente)
- while 1:
- msg = con.recv(1024)
- if msg:
- print('Cliente',cliente, \
- 'mandou', msg)
- else:
- break
- print("Finalizando conexão do cliente", cliente)
- con.close()
- def menu():
- escolha = int(input("[1] - Cliente"\
- "[2] - Servidor\nEscolha: "))
- if escolha == 1:
- cliente()
- elif escolha == 2:
- servidor()
- else:
- quit()
- menu()
Advertisement
Add Comment
Please, Sign In to add comment