1

現在、クローゼットにホームサーバーがあり、基本的に何もしていません。Ubuntu Server 8.0.4 がインストールされており、後で使用する Web 開発用の apache、ssh、および python/twisted がインストールされています。

問題は次のとおりです。

ソケット実装を使用して、「localhost」ポート 40 と通信するアプリを作成しました。 -ソケットベースの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()

したがって、本当の問題は、クライアントをサーバーなどに接続できないことです....申し訳ありませんが、私はネットワーキングに非常に慣れていません。

どんな意見でも役に立ちます。

4

1 に答える 1

1

If you've not established networking communication to your server from the internet before you'll want to establish that you can do that with simple test cases first, there's a lot that can stop traffic from the internet reaching your program on your server.

Is your server connected to the internet through a router? If so, can you communicate with the server from inside the local network (i.e. use the 192.168.xxx.xxx ip address), using something like netcat or telnet?

If that works you should try from outside the network (i.e. using the other ip address, from whatismyip.net or similar). If you've really no prior experience with networking you may have neglected to set up port forwarding, this is a setting on your router.

There are a lot of tutorials around teaching you how to set up a Ubuntu home server, I suggest learning how to host a (very) simple webpage as a means of learning how to network, this will help a lot with debugging a networked program like the one you're making.

于 2013-03-18T14:19:59.000 に答える