È possibile inviare un array tramite UDP Sockets utilizzando Python? Sto usando Python 2.5 e sto provando a inviare un array semplice ma non funziona. Può inviare correttamente l'array ma quando provo a stamparlo con un elemento dell'array il programma si blocca. Non sono sicuro di quale sia l'errore, perché prendo la precauzione di convertire i dati in un array ma non funziona. Spero di aver spiegato il problema nel modo più chiaro possibile. Apprezzerei l'aiuto!Invio e ricezione di array tramite socket
# Client program
from socket import *
import numpy
from array import*
# Set the socket parameters
host = "localhost"
port = 21567
buf = 4096
addr = (host,port)
# Create socket
UDPSock = socket(AF_INET,SOCK_DGRAM)
def_msg = "===Enter message to send to server===";
print "\n",def_msg
a = array('i',[1,3,2])
# Send messages
while (1):
data = raw_input('yes or now')
if data!= "yes":
break
else:
if(UDPSock.sendto(a,addr)):
print "Sending message"
# Close socket
UDPSock.close()
# Server program
from socket import *
# Set the socket parameters
host = "localhost"
port = 21567
buf = 4096
addr = (host,port)
# Create socket and bind to address
UDPSock = socket(AF_INET,SOCK_DGRAM)
UDPSock.bind(addr)
# Receive messages
while 1:
data,addr = UDPSock.recvfrom(buf)
L = eval(data)
if not data:
print "Client has exited!"
break
else:
print "\nReceived message '", L[1],"'"
# Close socket
UDPSock.close()
Funziona, grazie! – dawnoflife