Created
October 20, 2021 20:39
-
-
Save HectorSaldes/a71902166bfb0d26ce85572fce2cd070 to your computer and use it in GitHub Desktop.
[Sockets - chat] - Archivo para el levantamiento y recepción de transferencia de datos
This file contains hidden or 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
""" | |
? Saldaña Espinoza Hector | |
* Seguridad informática | |
! 7B | |
""" | |
import socket | |
def main(): | |
# * Se mantiene activo el servidor | |
server_socket = socket.socket() | |
server_socket.bind((str('localhost'), int(5000))) | |
server_socket.listen(5) | |
print("### Servidor de sockets activo ###") | |
conn, addr = server_socket.accept() | |
print(f'Conexión establecida con: {addr}') | |
# * Se realiza y se mantiene artiva la conexión | |
while True: | |
try: | |
# * Se mantiene activo el chat | |
while True: | |
sms = conn.recv(1024) | |
sms = sms.decode('UTF-8') | |
print(f'Mensaje entrante: {sms}') | |
conn.sendall(sms.encode('UTF-8')) | |
if(sms == 'q' or sms == 'Q'): | |
break | |
except: | |
break | |
finally: | |
conn.close() | |
print('Conexión finalizada') | |
# * Manda a ejecutar la función principal | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment