我正在玩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函数给我带来麻烦。
如果您需要代码的其他部分,请尽快回复并生病。
答案 0 :(得分:1)
我也遇到了麻烦。 您需要将所有文件(图像代码)放在同一个位置,如文件夹或桌面。希望我帮忙!