Primeira aula de sockets com configuração do cliente
This commit is contained in:
@@ -5,11 +5,11 @@ from socket import *
|
|||||||
cliente = socket(AF_INET,SOCK_STREAM)
|
cliente = socket(AF_INET,SOCK_STREAM)
|
||||||
|
|
||||||
#Abrir conexão
|
#Abrir conexão
|
||||||
conexao = cliente.connect(("127.0.0.1",3000))
|
conexao = cliente.connect(("10.209.1.45",3000))
|
||||||
|
|
||||||
#Enviar mensagem
|
#Enviar mensagem
|
||||||
cliente.send("Olá, servidor!".encode())
|
cliente.send("Olá, servidor! Aqui é o Simon".encode())
|
||||||
|
|
||||||
#
|
#
|
||||||
mensagem = cliente.recv(1024)
|
mensagem = cliente.recv(1024)
|
||||||
print(f"MEnsagem recebida {mensagem.decode()}")
|
print(f"Mensagem recebida {mensagem.decode()}")
|
||||||
@@ -7,6 +7,8 @@ servidor = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|||||||
#Estabelecer vinculo com endereço e uma porta
|
#Estabelecer vinculo com endereço e uma porta
|
||||||
servidor.bind(("127.0.0.1",3000))
|
servidor.bind(("127.0.0.1",3000))
|
||||||
|
|
||||||
|
print("Servidor inicializando...")
|
||||||
|
|
||||||
#Começa a ouvir tentativas de conexão
|
#Começa a ouvir tentativas de conexão
|
||||||
servidor.listen()
|
servidor.listen()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user