Re: socket policy flash help

2009-08-03 Thread NighterNet
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 = ;
 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-policyallow-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


Re: socket policy flash help

2009-08-02 Thread Piet van Oostrum
 NighterNet darkne...@gmail.com (N) wrote:

N Here the full code.
N flashpolicy.xml
N [[[
N ?xml version=1.0?
N cross-domain-policy
Nallow-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 import socket
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 = ;

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; #socket client
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 ('error socket %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-policyallow-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 flash socket
N to agrees with the connection.

-- 
Piet van Oostrum p...@cs.uu.nl
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: socket policy flash help

2009-08-01 Thread paul

NighterNet schrieb:

I need help on the policy to able to let access to user to the server
once the policy access is finish. I been trying to find a good
example, but I got no luck. Using python version 3.1.

Here the code I tested but it not working.

if str(buff) == str(b\'policy-file-request/\\x00\'):
print ('policy FOUND  sending...')
rawinput = str('?xml 
version=\1.0\?cross-domain-policyallow-
access-from domain=\*\ to-ports=\*\ //cross-domain-policy')
print (rawinput)
b = bytes ( ord(c) for c in rawinput)
self.sockfd.send(b);

And the error is? Doesn't Flash use http as transport?

cheers
 Paul

--
http://mail.python.org/mailman/listinfo/python-list


Re: socket policy flash help

2009-08-01 Thread Piet van Oostrum
 NighterNet darkne...@gmail.com (N) wrote:

N I need help on the policy to able to let access to user to the server
N once the policy access is finish. I been trying to find a good
N example, but I got no luck. Using python version 3.1.

N Here the code I tested but it not working.

N if str(buff) == str(b\'policy-file-request/\\x00\'):

What is buff supposed to contain here? I assume a byte sequence?
Do you reaaly mean that buff[0] contains the byte 'b' and buff[1]
contains a single quote? And the last byte also a single quote? And the
four bytes with \ x 0 0 before that instead of a null byte? In total 29 bytes?

Or did you mean just the 23 bytes long b'policy-file-request/\x00'?

Maybe it should be if buff == b'policy-file-request/\x00':

N print ('policy FOUND  sending...')
N rawinput = str('?xml 
version=\1.0\?cross-domain-policyallow-access-from domain=\*\ 
to-ports=\*\ //cross-domain-policy')

The str here is unnecessary as you have already a string.

N print (rawinput)
N b = bytes ( ord(c) for c in rawinput)

Why not 
b = b'?xml version=\1.0\?cross-domain-policyallow-access-from 
domain=\*\ to-ports=\*\ //cross-domain-policy' ?

N self.sockfd.send(b);

-- 
Piet van Oostrum p...@cs.uu.nl
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: socket policy flash help

2009-08-01 Thread NighterNet
On Aug 1, 4:52 am, Piet van Oostrum p...@cs.uu.nl wrote:
  NighterNet darkne...@gmail.com (N) wrote:
 N I need help on the policy to able to let access to user to the server
 N once the policy access is finish. I been trying to find a good
 N example, but I got no luck. Using python version 3.1.
 N Here the code I tested but it not working.
 N if str(buff) == str(b\'policy-file-request/\\x00\'):

 What is buff supposed to contain here? I assume a byte sequence?
 Do you reaaly mean that buff[0] contains the byte 'b' and buff[1]
 contains a single quote? And the last byte also a single quote? And the
 four bytes with \ x 0 0 before that instead of a null byte? In total 29 bytes?

 Or did you mean just the 23 bytes long b'policy-file-request/\x00'?

 Maybe it should be if buff == b'policy-file-request/\x00':

 N                               print ('policy FOUND  sending...')
 N                               rawinput = str('?xml 
 version=\1.0\?cross-domain-policyallow-access-from domain=\*\ 
 to-ports=\*\ //cross-domain-policy')

 The str here is unnecessary as you have already a string.

 N                               print (rawinput)
 N                               b = bytes ( ord(c) for c in rawinput)

 Why not
 b = b'?xml version=\1.0\?cross-domain-policyallow-access-from 
 domain=\*\ to-ports=\*\ //cross-domain-policy' ?

 N                               self.sockfd.send(b);

 --
 Piet van Oostrum p...@cs.uu.nl
 URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4]
 Private email: p...@vanoostrum.org


I try that method and flash socket is not getting the policy.

b = b'?xml version=\1.0\?cross-domain-policyallow-access-from
domain=\*\ to-ports=\*\ //cross-domain-policy'
self.sockfd.send(b);

server = socket.socket( socket.AF_INET, socket.SOCK_STREAM)

When it able to read the policy it send it but it fail to send to
flash some reason and send it again and then d/c.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: socket policy flash help

2009-08-01 Thread NighterNet
Here the full code.

flashpolicy.xml
[[[
?xml version=1.0?
cross-domain-policy
   allow-access-from domain=* to-ports=* /
/cross-domain-policy
]]]

flashpolicytest_server3x.py
[[[

#!/usr/local/bin/python
'''
Still under testing...
python version 3.x.x
'''
import socket
import threading
import sys
import os

file_name = 'flashpolicy.xml'
fh = open(file_name, r)
policy = fh.read(10001)

host = ''; #out side network
port = ;

print (#  - Init... -  #);
class ClientThread (threading.Thread):
global policy;
allClients = [];
vlock = threading.Lock();
id = 0 # next available thread number
def __init__(self,clientSocket):
threading.Thread.__init__(self)
self.sockfd = clientSocket; #socket client
self.name = '';
ClientThread.id += 1
self.id = ClientThread.id
self.nickName = '';
self.allClients.append(self.sockfd);
def sendAll(self,buff):
for index,clientSock in enumerate(self.allClients):
try:
clientSock.send(buff);
except (socket.error):
print ('error socket %s\n',index,| clean);
clientSock.close()
del self.allClients[index]
def run(self):
while True:
buff = self.sockfd.recv(1028);
if not buff:
print (connect close...(client side));
self.sockfd.close();
break #incase it loop infinite
if str(buff) == str(b\'policy-file-request/\\x00\'):
print ('policy FOUND  sending...')
print(buff)
b = b'?xml 
version=\1.0\?cross-domain-policyallow-access-
from domain=\*\ to-ports=\*\ //cross-domain-policy'
print (b)
self.sockfd.send(b);
self.sockfd.sendall(b);
print(buff);
self.sendAll(buff)
self.sockfd.close()
print (#  - Init... Listen Client -  #\n);
try:
server = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
except AttributeError:
# AttributeError catches Python built without IPv6
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error:
# socket.error catches OS with IPv6 disabled
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server.bind((host,port))
server.listen(5)
print (Server Up Listen!,host,:,port, Bind!);
while True:
(clientSocket, address) = server.accept();
print(client connect from :,address);
ct = ClientThread(clientSocket);
print(ct.id);
ct.start();

]]]

Some odd reason I can't send flash policy from python to flash socket
to agrees with the connection.
-- 
http://mail.python.org/mailman/listinfo/python-list


socket policy flash help

2009-07-31 Thread NighterNet
I need help on the policy to able to let access to user to the server
once the policy access is finish. I been trying to find a good
example, but I got no luck. Using python version 3.1.

Here the code I tested but it not working.

if str(buff) == str(b\'policy-file-request/\\x00\'):
print ('policy FOUND  sending...')
rawinput = str('?xml 
version=\1.0\?cross-domain-policyallow-
access-from domain=\*\ to-ports=\*\ //cross-domain-policy')
print (rawinput)
b = bytes ( ord(c) for c in rawinput)
self.sockfd.send(b);
-- 
http://mail.python.org/mailman/listinfo/python-list