나는 한동안 twisted 프레임 워크를 사용하여 서버에서 클라이언트로 파일을 전송하는 방법을 찾고 있었지만 유용한 것은 없습니다.트위스트 프레임 워크를 사용하여 클라이언트에게 파일을 보냅니다.
난 그냥 사용자에 대한 이미지를 보내려면 내 경우, 그것은 채팅 응용 프로그램 있고 난 이미지 [내가 서버가 어디에]
다음무엇을이다 또는 내가 노력하고 있어요] 로컬에 저장하고 나는했다 :
from twisted.internet import reactor
from twisted.internet.protocol import Factory , Protocol
class IphoneChat(Protocol):
def connectionMade(self):
self.factory.clients.append(self)
def connectionLost(self , reason):
self.factory.clients.remove(self)
def dataReceived(self,data):
a = data.split(':')
contor = 0
command = a[0]
content = a[1]
if command == "saveimage":
personName = a[1]
contentData = a[2]
escape = a[3]
location = "person-images/"+str(personName)+".jpg"
try:
f = open (location,'w+')
f.write(contentData)
except :
self.transport.write("error when opening the file")
elif command == "getimage" :
picture = a[1]
extra = a[2]
location = "person-images/"+picture+".png"
try:
self.transport.write("image:")
for bytes in read_bytes_from_file(location) :
self.transport.write(bytes)
self.transport.write('\r\n')
except :
self.transport.write('no such file\r\n')
factory = Factory()
factory.protocol=IphoneChat
factory.clients = []
reactor.listenTCP(8023,factory)
print "IPhone Chat server started"
reactor.run()
그러나 클라이언트 [iOS 응용 프로그램]에서 이상한 동작이 나타나고 동작이 작동하지 않는다는 것입니다. iosApp에서
뭔가 :
var binaryData: NSData
let string : NSString = output.componentsSeparatedByString(":")[0] as NSString
binaryData = string.dataUsingEncoding(NSUTF8StringEncoding)!
var data = UIImage(data: binaryData)
self.personImage.image = data
self.personImage.hidden = true
는 서버 측 또는 클라이언트의 문제인가?
* 또한 작동하지 않습니다 *를 정의하고 이미지를 검색/표시하기 위해 iOS 앱에 사용 된 코드를 포함하십시오. –
좋아. 잠깐. 첫 코멘트에 무슨 말을했는지 보여 줄 수 있니? – tudoricc
신경 쓰지 마라, 나는 당신이 HTTP 서버를 구현하고 있다고 생각했지만, 당신이 자신의 프로토콜을 사용하고있는 것처럼 보였으므로 나의 첫 코멘트는 부적절하다. –