目前,我的衣柜里有一台家庭服务器,基本上什么都不做。它安装了 Ubuntu Server 8.0.4,稍后将使用用于 Web 开发的 apache,ssh 和 python/twisted。
这是问题:
我创建了一个应用程序来与“localhost”端口 40 对话,使用套接字实现,这是我所做的但我想要开发的链接:http ://www.raywenderlich.com/3932/how-to -create-a-socket-based-iphone-app-and-server
现在连接到本地主机没问题,但我想扩展它以与我的服务器一起使用。
我在我的服务器上实现了 python 协议并更改了我在 iOS 应用程序中访问的 IP 地址。这是我的实现,除了我正在访问的端口外,它与教程完全相同。
from twisted.internet.protocol import Factory, Protocol
from twisted.internet import reactor
class IphoneChat(Protocol):
def connectionMade(self):
self.factory.clients.append(self)
print "clients are ", self.factory.clients
def connectionLost(self, reason):
self.factory.clients.remove(self)
def dataReceived(self, data):
a = data.split(':')
print a
#b = password.split(':')
#print b
if len(a) > 1:
command = a[0]
content = a[1]
#username = a[2]
#password = a[2]
msg = ""
#msg2 = ""
if command == "username":
self.name = data
msg = self.name + " has joined"
#self.name = password
#msg2 = self.name + " this is his password"
#print msg
elif command == "password":
self.name = data
msg = self.name + " this is their password"
elif command == "msg":
msg = self.name + ": " + data
print msg
#msg2 = self.name + ": " + password
#print msg2
for c in self.factory.clients:
c.message(msg)#1, msg2)
def message(self, message):
self.transport.write(message + '\n')
factory = Factory()
factory.protocol = IphoneChat #here1#
factory.clients = []
reactor.listenTCP(40, factory)
print "Iphone Chat server started"
reactor.run()
所以真正的问题是,我无法将客户端连接到我的服务器或其他东西......我很抱歉,但我对网络很陌生。
任何意见都会有所帮助。