You Are Here:

Community: Developer Discussion Boards

#1 Old very strange problem with marshal - 2008-05-16, 12:32

Join Date: Mar 2008
Posts: 25
sstoica
Offline
Registered User
hello,
I get a very strange problem with marshal when trying to serialize a big list and send it over a socket. It works ok on a pc-pc comunication, but it gives an EOF error when moving the client on the emulator:

the problem is that i can send the small and medium sized lists, but i get and EOFError: EOF read where object expected when i try to send the big list.

Can anyone see where's the problem ?

here's my (simple) test code:

server:

Code:
from socket import *
import marshal
import sys
sys.path.append("C:\customlibs")
import objparser

myHost = ''
myPort = 2000

s = socket(AF_INET, SOCK_STREAM)    # create a TCP socket
s.bind((myHost, myPort))            # bind it to the server port
s.listen(5)                         # allow 5 simultaneous
                                    # pending connections
stop = 0
stopconnection = 0

vertice_to_send = []
indice_to_send = []
string_to_send = [ (1,2,3) ]

#parse the obj
file = open ("C:\sphere.obj", "r")
parser = objparser.objParser()
parser.parse_file(file)
file.close()

vertice_to_send = marshal.dumps ( parser.get_vertices() )
indice_to_send = marshal.dumps ( parser.get_indices() )

print len(vertice_to_send)
print len(indice_to_send)
print len(marshal.dumps(string_to_send))


while not stop:
    # wait for next client to connect
    print "waiting for connection..."

    stop = 0
    stopconnection = 0
    connection, address = s.accept() # connection is a new socket
    print "connection accepted from", address

    while not stopconnection:
        print "after connection accepted"

        data = connection.recv(1024) # receive up to 1K bytes    
        if data:
            print data," recieved from ", address
        
            if data == "killme":
                stop = 1
                stopconnection = 1
                break

            elif data == "get_sphere_vertices":
                connection.send(vertice_to_send)
                print "after vertices sent"

            elif data == "get_sphere_indices":
                connection.send(indice_to_send)
                print "after indices sent"

            elif data == "test":
                connection.send( marshal.dumps(string_to_send) )
                print "after test sent"
            
        else:
            print "connection closed"
            stopconnection = 1

connection.close()              # close socket

client:

Code:
import marshal
from socket import *

serverHost = 'localhost'
serverPort = 2000


if __name__ == '__main__':

    file = open(u'C:\\emu_data_streamed.txt','a')

    s = socket(AF_INET, SOCK_STREAM)
    s.connect((serverHost, serverPort))

    """
    #test sending a small list (len = 25)
    s.send("test") 
    data = marshal.loads( s.recv(10240) ) #10K of data
    print data
    file.write( str(data) )
    """
    """ 
    #test sending a medium-sized list (len = 3845)
    s.send("get_sphere_indices") 
    data = marshal.loads( s.recv(10240) ) #10K of data
    print data
    file.write( str(data) )
    
    """
    #test sending a big list (len = 8645)
    s.send("get_sphere_vertices") 
    data = marshal.loads( s.recv(10240) ) #10K of data
    print data
    file.write( str(data) )
Last edited by sstoica : 2008-05-16 at 14:17.
Reply With Quote

#2 Old Re: very strange problem with marshal - 2008-05-16, 15:08

Join Date: Mar 2008
Posts: 25
sstoica
Offline
Registered User
Ok, so the length of the big list is 432. If I try
Code:
vertice_to_send = marshal.dumps ( parser.get_vertices()[0:409])
to send the first 409 elements of the list, it works. For more

Code:
vertice_to_send = marshal.dumps ( parser.get_vertices()[0:410])
I get the EOF error. I don't understand...
Reply With Quote

#3 Old Re: very strange problem with marshal - 2008-05-16, 17:21

Join Date: Mar 2008
Posts: 25
sstoica
Offline
Registered User
ok, case sovled. if anyone is interested, the reading from the socket should be put in a while until you are SURE you've read all. s.recv(10240) doesn't guarantee that you actualy read all the data in this case (~8500).
Code:
while len(data) < msg_length:
        data += s.recv(1024) #1K of data
also, close the file at the end after writing to it !
Reply With Quote

#4 Old Re: very strange problem with marshal - 2008-05-20, 21:54

Join Date: Mar 2003
Posts: 937
Location: Espoo, Finland
JOM's Avatar
JOM
Offline
Forum Nokia Champion
Quote:
Originally Posted by sstoica View Post
reading from the socket should be put in a while until you are SURE you've read all. s.recv(10240) doesn't guarantee that you actualy read all the data
Usually socket data is buffered, that's true. When looking at e32socketmodule.cpp there's "#define MaxBufferSize 1024", which most likely defines internal buffer size as one kilo.

However did you notice you could have requested some buffer size by yourself, in theory at least:

Code:
    def recv(self, n, f=0, cb=None):
        self._recvsizehint=n
Cheers,

--jouni
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange problem "java.lang.Error 105" aadipa Mobile Java General 6 2009-10-22 10:21
Strange problem while installing Carbide.C++ express jugnoyasir Carbide.c++ IDE and plug-ins 4 2008-10-06 21:19
strange problem !!! metebalci Mobile Java General 0 2005-09-30 09:41
VERY strange memory full problem.. etamburini Mobile Java General 9 2005-05-17 16:50
very strange problem victorh81 General Symbian C++ 1 2003-12-09 10:09

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia