Пример #1
0
except socket.error:
    print ('Falla al Crear Socket')
    sys.exit()
 
host = 'localhost';
port = 7890;

formulario = Form()
nombre = formulario.getName()
apellido = formulario.getLastName()
ci = formulario.getCI()
f_n = formulario.getDate()
lugar_n = formulario.getPlace()
f_array = formulario.getFotoArray() #bytes de la foto 
#array de bytes de la foto
obj = formulario.getSerialize()
b=True
while(b) :
    
    try :
        #Set the whole string
        s.sendto(obj, (host, port)) #msg.encode()
        # for x in f_array:
        #     s.sendto(x, (host, port))
        #s.sendto('fin'.encode(), (host, port))
        #s.sendto(foto, (host, port))
         
        #receive data from client (data, addr)
        d = s.recvfrom(1024)
        reply = d[0]
        addr = d[1]
Пример #2
0
# Create the datagram socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)


# Set a timeout so the socket does not block indefinitely when trying
# to receive data.
sock.settimeout(60)

# Set the time-to-live for messages to 1 so they do not go past the
# local network segment.
ttl = struct.pack('b', 1)
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, ttl)

form = Form()
message = form.getSerialize()

try:

    # Send data to the multicast group
    #print ( 'sending "%s"' % message)
    sent = sock.sendto(message, multicast_group)

    # Look for responses from all recipients
    while True:
        print('esperando una respuesta')
        try:
            data, server = sock.recvfrom(160)
        except socket.timeout:
            print( 'tiempo de espera terminado, sin respuesta')
            break