想在python中使用套接字发送图像文件

时间:2016-10-04 18:45:48

标签: python sockets

使用来自PIL文件夹的名为ImageGrab的库,我试图截取服务器屏幕并将其发送给客户。我将截图保存在一个文件夹中,但如何发送?如果图像尺寸太大,我该如何将其拆分并将其分片发送给客户?

服务器端:

import socket
from PIL import ImageGrab

server_socket = socket.socket()
server_socket.bind('0.0.0.0', 8820)
server_socket.listen(1)

(client_socket, client_address) = server_socket.accept()
print client_address + ' Have connected to server'
commend = client_socket.recv(1024)
while commend != 'exit':
    if commend == 'screenShot':
        im = ImageGrab.grab()
        im.save(r'C:\screen.jpg')


server_socket.close()

客户端:

    import socket

my_socket = socket.socket()
my_socket.connect('127.0.0.1', 8820)

commend = raw_input('Connected! Enter your commend')
my_socket.send(commend)



my_socket.close()

求助

0 个答案:

没有答案