Skip to content

Commit

Permalink
feat: stablishing socket conection btw client and server
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinator47 committed Jan 14, 2025
1 parent 127a620 commit 4c3ca37
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
23 changes: 23 additions & 0 deletions client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from socket import *

# Nombre del servidor y puerto para establecer la conexion
server_name = 'localhost'
server_port = 12000

# crea el socket para establecer la comunicacion(ip4 y TCP)
client_socket = socket(AF_INET, SOCK_STREAM)

#handshake inicial entre cliente y servidor
client_socket.connect((server_name,server_port))

# -- Implementar protocolo FTP --
# Esto de momento es una prueba mandando tu nombre para que el server te salude
name = input('Ingrese su nombre: ')
client_socket.send(name.encode())

response = client_socket.recv(1024).decode()
print(response)

# cierra la conexion
client_socket.close()

23 changes: 23 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from socket import *

# levantando el servidor
server_port = 12000
server_socket = socket(AF_INET, SOCK_STREAM)
server_socket.bind(('' , server_port))
server_socket.listen(1)

print("Server Ready...")

# escuchando conexiones de clientes
while True:
connection_socket , addr = server_socket.accept() #conexion establecida

# -- Implementar protocolo FTP --
# -- de momento como prueba, recibe un nombre y manda un saludo
name = connection_socket.recv(1024).decode()
response = "Server says: hello, " + name
connection_socket.send(response.encode())
connection_socket.close()



0 comments on commit 4c3ca37

Please sign in to comment.