On Aug 2, 12:25 pm, Piet van Oostrum <p...@cs.uu.nl> wrote: > >>>>> NighterNet <darkne...@gmail.com> (N) wrote: > >N> Here the full code. > >N> flashpolicy.xml > >N> [[[ > >N> <?xml version="1.0"?> > >N> <cross-domain-policy> > >N> <allow-access-from domain="*" to-ports="*" /> > >N> </cross-domain-policy> > >N> ]]] > >N> flashpolicytest_server3x.py > >N> [[[ > >N> #!/usr/local/bin/python > >N> ''' > >N> Still under testing... > >N> python version 3.x.x > >N> ''' > >N> importsocket > >N> import threading > >N> import sys > >N> import os > >N> file_name = 'flashpolicy.xml' > >N> fh = open(file_name, "r") > >N> policy = fh.read(10001) > > You never use that variable. > > > > >N> host = ''; #out side network > >N> port = 5555; > >N> print ("# ------------- Init... ------------- #"); > >N> class ClientThread (threading.Thread): > >N> global policy; > >N> allClients = []; > >N> vlock = threading.Lock(); > >N> id = 0 # next available thread number > >N> def __init__(self,clientSocket): > >N> threading.Thread.__init__(self) > >N> self.sockfd = clientSocket; #socketclient > >N> self.name = ''; > >N> ClientThread.id += 1 > >N> self.id = ClientThread.id > >N> self.nickName = ''; > >N> self.allClients.append(self.sockfd); > >N> def sendAll(self,buff): > >N> for index,clientSock in enumerate(self.allClients): > >N> try: > >N> clientSock.send(buff); > > There is no guarantee that send will indeed transmit all of buff. It is > better to use clientSock.sendall(buff). Or you should check the return > value of send and check if it is equal to the length of buff. And repeat > if not. (But sendall is easier). > > Also don't use ; at the end of the statement. It's not pythonic. > > >N> except (socket.error): > >N> print ('errorsocket%s\n',index,"| clean"); > >N> clientSock.close() > >N> del self.allClients[index] > >N> def run(self): > >N> while True: > >N> buff = self.sockfd.recv(1028); > > There is no guarantee that recv will get the whole message. It may even > get as little as 1 byte. So you should check the return value of recv. > The official way is to keep reading until you have enough input or until > you hit end of file. > > >N> if not buff: > >N> print ("connect close...(client side)"); > >N> self.sockfd.close(); > >N> break #incase it loop infinite > >N> if str(buff) == > >str("b\'<policy-file-request/>\\x00\'"): > > What you check here is whether buff contains the byte sequence that starts > with a > b, then a ' ... and ending with the 5 bytes \ x 0 0 ' which is wrong. > > Actually it should be: > > if buff == b\'<policy-file-request/>\x00': > or > if buff == b\'<policy-file-request/>\0': > > >N> print ('policy FOUND >>> sending...') > >N> print(buff) > >N> b = b'<?xml > >version=\"1.0\"?><cross-domain-policy><allow-access- > >N> from domain=\"*\" to-ports=\"*\" /></cross-domain-policy>' > >N> print (b) > >N> self.sockfd.send(b); > >N> self.sockfd.sendall(b); > > Only self.sockfd.sendall; delete the line with self.sockfd.send(b). And > remove the semicolons for esthetical reasons. > > >N> Some odd reason I can't send flash policy from python to flashsocket > >N> to agrees with the connection. > > -- > Piet van Oostrum <p...@cs.uu.nl> > URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4] > Private email: p...@vanoostrum.org
thanks it help. I was not sure about the format most the time. -- http://mail.python.org/mailman/listinfo/python-list