socket + file i/o question

J

John

I am sending a file on a tcp socket using the following code


while 1:
buf = os.read(fd, 4096)
if not buf: break
print total, len(buf)
conn.send(buf)

The recieving code looks like

while 1:
if recvbytes == filesize:
print 'Transfer done. Size = %d' % recvbytes
break
buf = s.recv(4096)
if not buf:
print 'EOF received'
raise Exception()
print recvbytes, len(buf)
os.write(fd, buf)
recvbytes = recvbytes + len(buf)


My problem is that the first time the client uploads a file
to the server, the code works. But then when the server wants
to download a file to the client, the same code breaks down!

The problem seems to be the socket. The send part sends exactly the
amount of data it reads from the file. But the recv part gets one
more byte than the size of the file?? It seems to me that this
extra one byte is coming inside the send/recv calls. Anyone has
any comments on where this extra one byte is coming from?

Thanks a lot for your help,
--j
 
J

John

Here is what the send and recieved number of bytes show up as:

Filesize being sent = 507450
Server sending file to client...
(total size sent , buffer size)
....
491520 4096
495616 4096
499712 4096
503808 3642
../server.py: (107, 'Transport endpoint is not connected')

On the client side, the bytes recieved shows one extra byte!
(Bytes recieved, buffer size)
....
504256 1400
504256 1400
505656 1400
505656 1400
507056 1400
507056 395
507451 395
EOF received
../client.py: An unknown error occurred.

Note that on the client there was an extra byte??
507451 ??

Hope this helps in explaining my question better,
--j
 
J

John

I found the problem. There was a recv that was not from an open
socket...

Sorry abt the trouble,
--j
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top