Ejercicio TCP

master
vicsash 10 months ago
commit de5e3a31d7

8
.idea/.gitignore vendored

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/test" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (TCP)" project-jdk-type="Python SDK" />
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/TCP.iml" filepath="$PROJECT_DIR$/.idea/TCP.iml" />
</modules>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

@ -0,0 +1,20 @@
import socket
HOST = '127.0.0.1'
PORT = 2000
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((HOST, PORT))
print('Conectado con éxito')
while True:
message = input("Enter a message (or 'exit' to quit): ")
if message.lower() == 'exit':
break
s.sendall(message.encode('utf-8'))
num_bytes_sent = len(message.encode('utf-8'))
print(f"Sent {num_bytes_sent} bytes")
data = s.recv(1024) # línea bloqueante
print('Recibido:', repr(data.decode('utf-8')))

@ -0,0 +1,15 @@
import socket
HOST = '' # todas las interfaces locales a la escucha
PORT = 2000 # Puerto de escucha
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((HOST, PORT))
s.listen()
conn, addr = s.accept() #línea bloqueante
with conn:
print(f"Conexión exitosa con el cliente. IP ({addr[0]}) Puerto ({addr[1]})")
while True:
data = conn.recv(1024) #línea bloqueante
print (data)
if data==b"0":
break
conn.sendall(b"mensaje recibido")
Loading…
Cancel
Save

Powered by INFORMATICA.FP.EDU.ES.