[Tutor] Practicing with sockets

Bo Morris crushed26 at gmail.com
Fri Oct 31 18:28:48 CET 2014


Hello all, hope everyone is doing well.

I have been practicing with sockets and I am trying to send a small png
from the client to the server.

the client code is...

import socket

f = open('/Users/Bo/Desktop/logo_ONEConnxt.png', 'rb')
strf = f.read()
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(("ip.ip.ip.ip", 8999))
client_socket.sendall(strf)
f.close()
exit()

and the server code is...

import socket

f = open('img.png', 'wb')
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
port = 8999
s.bind(('', port))
s.listen(5)

client_socket, address = s.accept()
data = client_socket.recv(4029)
f.write(data)
client_socket.close()

Both the above client and server code runs without error, however the
"img.png" file that is placed on the server shows zero bytes? Will someone
please show me what I am doing wrong?

Thank you,

Bo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20141031/65b9f3af/attachment.html>


More information about the Tutor mailing list