Primer Ejercicio y Echo

master
vicsash 10 months ago
commit 632df89519

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 (UDP)" 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/UDP.iml" filepath="$PROJECT_DIR$/.idea/UDP.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,23 @@
import socket
HOST = '127.0.0.1'
PORT = 2000
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
server_address = (HOST, PORT)
while True:
message = input("Enter a message (or 'exit' to quit): ")
if message.lower() == 'exit':
break
# Send the message
print('Sending {!r}'.format(message))
sent = s.sendto(message.encode('utf-8'), server_address)
# Receive the response
print('Waiting for the response')
data, server = s.recvfrom(1024) # línea bloqueante
print('Received {!r} from {}'.format(data.decode('utf-8'), server))
# Program ends when 'exit' is entered by the user

@ -0,0 +1,15 @@
import socket
HOST = ''
PORT = 2000
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
s_addr = (HOST, PORT)
s.bind(s_addr)
while True:
#recibir
datos, addr = s.recvfrom(1024) #línea bloqueante
print('recibidos {} bytes de {}'.format(len(datos), addr))
print(datos)
#enviar
if datos:
sent = s.sendto(b"Saludos desde el Servidor UDP", addr)
print('enviados {} bytes de vuelta a {}'.format(sent, addr))

@ -0,0 +1,15 @@
import socket
HOST = '127.0.0.1'
PORT = 2000
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
s_addr = (HOST, PORT)
server_address = (s_addr)
cadena = input("Por favor, introduce una cadena: ")
message = bytes(cadena, 'utf-8')
# enviar
print('Enviando {!r}'.format(message))
sent = s.sendto(message, server_address)
# recibir
print('Esperando por la respuesta')
data, server = s.recvfrom(1024) #línea bloqueante
print('recibidos {!r}'.format(data))

@ -0,0 +1,15 @@
import socket
HOST = ''
PORT = 2000
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
s_addr = (HOST, PORT)
s.bind(s_addr)
while True:
#recibir
datos, addr = s.recvfrom(1024) #línea bloqueante
print('recibidos {} bytes de {}'.format(len(datos), addr))
print(datos)
#enviar
if datos:
sent = s.sendto(datos.upper(), addr)
print('enviados {} bytes de vuelta a {}'.format(sent, addr))
Loading…
Cancel
Save

Powered by INFORMATICA.FP.EDU.ES.