我正在玩 pygame 和 WX 来进行一些自学项目,以提高我的技能。我正在尝试通过 python 2.7.3 中的套接字服务器发送 png 并将 png 加载到 pygame 中。我已经确认我可以通过 localhost 接收 png,但我无法加载我的 png。
这是给麻烦的 RDPC.py 文件:
import os
import sys
import pygame
from pygame.locals import *
from threading import Thread
import time
import socket
import shutil
def recvFile():
file = open("data2/screenshot.png","wb")
while 1:
data = s.recv(2048)
if not data:
break
file.write(data)
file.close()
shutil.copyfile('data2/screenshot.png', 'data2,screen.png')
image = pygame.image.load('data2/screen.png')
screen.blit(image,(0,0))
pygame.display.flip()
class RDPclient(object):
def main(self, rdpserver):
self.insert(rdpserver)
def insert(self, rdpserver):
done = False
while not done:
for event in pygame.event.get():
x,y = pygame.mouse.get_pos()
if event.type == MOUSEBUTTONDOWN:
rdpserver.mouse(x,y)
elif event.type == MOUSEMOTION:
if event.type == MOUSEBUTTONDOWN:
self.mouseDragEvent(x,y)
self.mouseMoveEvent(x,y)
if (event.type == KEYDOWN):
rdpserver.keyboard(event)
if (event.type == KEYUP):
rdpserver.keyboard(event)
if (event.key == K_ESCAPE):
done = True
def mouseDownEvent(self,x,y):
pass
def mouseUpEvent(self,x,y):
pass
def mouseDragEvent(self,x,y):
pass
def mouseMoveEvent(self,x,y):
pass
pygame.init()
screen = pygame.display.set_mode((1024,768), pygame.RESIZABLE)
white = (255, 255, 255)
screen.fill(white)
pygame.display.set_caption('PyRDP')
pygame.mouse.set_visible(1)
t_bytes = 1024*1024*1
HOST = '127.0.0.1'
PORT = 9999
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
rec = Thread(target=recvFile)
rec.start()
只有上面的代码 recvFile 函数给我带来了麻烦。
如果您需要代码的其他部分,请尽快回复并发布。