-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: stablishing socket conection btw client and server
- Loading branch information
1 parent
127a620
commit 4c3ca37
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
||
|
||
|