My program create a packet, then call the send function to send this. the first time the packet is not sent, then it works perfectly!
WHY??? Have you idea??
--
Sbaush
from socket import * from struct import * from string import * class SendReceive: def __init__(self): self.UDPSock = socket(AF_INET,SOCK_DGRAM) def receive(self,timeout): # Set the socket parameters buf = 100000 # Receive messages try: self.UDPSock.settimeout(timeout) xmlrcv,addr = self.UDPSock.recvfrom(buf) xmlrcv=xmlrcv[4:]#questo comando di slicing notation elimina i primi quattro bytes della stringa ricevuta, corrispondenti all'intero del pacchetto. (hostfrom,portfrom)=addr #print "Received response from ",hostfrom #print "on port ",portfrom #print xmlrcv return (xmlrcv,hostfrom) except : #print "TimeOut" return False #UDPSock.close()
def send(self,hostto,xml): try: name=hostto #name=raw_input('Insert IP or name to send command >> ') #"192.168.2.138" host=gethostbyname(name) port = 40004 buf = 5000 addr = (host,port) dtd="<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE meshap-manager PUBLIC \"\" \"MeshAP2.1.3.dtd\"> " xml=dtd+xml lenght=4+len(xml) packet=pack('i 5000s',lenght,xml) self.UDPSock.sendto(packet,addr) print "Sending message '",packet,"'.....<done>" #UDPSock.close() except: return False
-- http://mail.python.org/mailman/listinfo/python-list