Read / Write image file

C

codecraig

I have a image file on my pc, say a .jpg. Basically I want to setup a
client/server socket, and I want the client to read in the jpg and send
it to the server, where the server can write that data into a new file
on the server.

I tried just doing something like..

x = open("abc.jpg")
y = x.read()
tmp = open("newFile.jpg", "w")
tmp.write(y)
tmp.close()
x.close()

....but that doesn't give me a copy of abc.jpg

any ideas? Thanks
 
M

Maciej Dziardziel

codecraig said:
I have a image file on my pc, say a .jpg. Basically I want to setup a
client/server socket, and I want the client to read in the jpg and send
it to the server, where the server can write that data into a new file
on the server.

I tried just doing something like..

x = open("abc.jpg")
y = x.read()
tmp = open("newFile.jpg", "w")
tmp.write(y)
tmp.close()
x.close()

...but that doesn't give me a copy of abc.jpg

any ideas? Thanks

Give us more details. The code above works well for me. (python2.3).
 
M

Max M

codecraig said:
I have a image file on my pc, say a .jpg. Basically I want to setup a
client/server socket, and I want the client to read in the jpg and send
it to the server, where the server can write that data into a new file
on the server.

I tried just doing something like..

x = open("abc.jpg")
y = x.read()
tmp = open("newFile.jpg", "w")
tmp.write(y)
tmp.close()
x.close()

...but that doesn't give me a copy of abc.jpg

any ideas? Thanks

x = open("abc.jpg", 'rb')

--

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
 
C

codecraig

well on the server, if I have,

x = sock.recv(1024) ....and the client sends more than 1024 bytes...the
server won't receive it all right? So I am wondering, how do I setup
the server to handle some unknown amount of data?

Note, in previous post it should have been, x = sock.recv(1024) not x =
server.recv(1024)

thanks
 

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

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top