| Reply | « Previous Thread | Next Thread » |
|
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.
|
|
Ok, so the length of the big list is 432. If I try
Code:
vertice_to_send = marshal.dumps ( parser.get_vertices()[0:409]) Code:
vertice_to_send = marshal.dumps ( parser.get_vertices()[0:410]) |
|
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
|
|
Quote:
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
--jouni |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| 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 |