Gabriel Rossetti wrote:
Hello everyone,

I get a (11, 'Resource temporarily unavailable') error when I try to send a file using a socket. Is there s size limit? I tried sending a smaller file and ii poses no problem. Am I doing something wrong? Here is the code:

def sendMessage(host, port, msg):

   if isinstance(msg, unicode):
       msg = msg.encode("utf-8")
     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   sock.connect((host, port))
   sock.setblocking(0)
   totalsent = 0
   while totalsent < len(msg):
       sent = sock.send(msg[totalsent:])
       if sent == 0:
           raise RuntimeError, "socket connection broken"
       totalsent = totalsent + sent
   sock.close()

Thank you,
Gabriel

Actually, the original code didn't have the sock.setblocking(0), the problem I am trying to find is that the server does have sock.setblocking(0) (I can't change that) and it is getting the same error as my client has with the sock.setblocking(0), except it gets it on the accept() call. I tried modifying my code to be like this :

def sendMessage(host, port, msg):
if isinstance(msg, unicode):
       msg = msg.encode("utf-8")
burstSize = 4096 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   sock.connect((host, port))
   while msg:
       sent = sock.send(msg[:burstSize])
       print "Sending %d bytes..." % sent
       if sent == 0:
           raise RuntimeError, "socket connection broken"
       msg = msg[burstSize:]
   sock.close()

thinking maybe if I send small parts it would work better but this does not seem to change anything. How are large msgs sent w/ a socket in python to a non-blocking server? The msg I'm trying to send is 175213 bytes long.

Thank,
Gabriel
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to