그래서 2 개의 iOS 앱 (하나는 좌표 전송, 하나는 수신)과 Python 서버를 만들었습니다. 애플 리케이션 중 하나는 heroku에서 호스팅되는 내 python 서버에 GPS 좌표를 보냅니다. 그러면 서버는 수신 된 GPS 좌표를 다른 iOS 클라이언트 응용 프로그램에 내 보내어 수신 된 좌표에 Apple지도 핀을 놓습니다.heroku python 앱에 사용할 포트
프로젝트는 지정된 포트가있는 로컬 호스트에서 테스트하는 동안 완벽하게 작동합니다. 그러나 내가 Heroku 서버를 마이그레이션했을 때 this error 오류가 발생합니다. Heroku가 자신의 포트를 사용하도록 설정했기 때문에 오류가 발생합니다. 내 코드가 사용할 포트를 지정했기 때문입니다. 그래서 초심자 인 Python과 Twisted 스킬 덕분에 os.environ["PORT"]을 사용하는 다른 사람들의 솔루션을 구현하기 위해 수많은 시간 동안 찾아 보았습니다. 그러나 iOS 앱을 제대로 사용하기 위해 Heroku 서버와 통신하는 데 성공하지 못했습니다. 오른쪽 포트. 내 서버 코드는 다음과 같습니다. (참고 : Twisted를 사용하고 있습니다.)
import os
from twisted.internet.protocol import Protocol, Factory
from twisted.internet import reactor
class IphoneChat(Protocol):
def connectionMade(self):
#self.transport.write("""connected""")
self.factory.clients.append(self)
print "clients are ", self.factory.clients
def connectionLost(self, reason):
self.factory.clients.remove(self)
def dataReceived(self, data):
#print "data is ", data
a = data.split(':')
if len(a) > 1:
command = a[0]
content = a[1]
msg = ""
if command == "new":
self.name = content
msg = content
elif command == "msg":
msg = self.name + ": " + content
print msg
for c in self.factory.clients:
c.message(msg)
def message(self, message):
self.transport.write(message + '\n')
factory = Factory()
factory.protocol = IphoneChat
factory.clients = []
port = 3000
reactor.listenTCP(port, factory)
print "Iphone Chat server started on port ", port
reactor.run()
안녕하세요 닐 :
같은 것을 포함 할 자신의 코드로 구현! 답장을 보내 주셔서 감사합니다. 나는 당신의 솔루션을 구현했지만, "60 초 내에 오류를 일으키지 못했습니다."[link] (http://i.imgur.com/WmgOIaD.png?1) – Aimee
@Aimee는 당신이 ' heroku 대시 보드에서 변수를 올바르게 설정 했습니까? [this] (https://www.dropbox.com/s/7w6l6dwsqt5kz89/checkthis.png?dl=0)와 같이 보입니다. –
@Aimee 또한 os 변수가 올바른 데이터를 얻고 있는지 확인해야 할 수도 있습니다. 'PORT' 키를 찾지 못하면 (Harry Potter quint at nointentional) _5000으로 기본 설정되며 Heroku가 설정하지 않은 경우 문제가 발생할 수 있습니다. 원래 정보는 Heroku docs [여기] (https://blog.heroku.com/archives/2011/9/28/python_and_django)의 플라스크 튜토리얼에서 발견되었습니다. –