这是错的吗?
from SimpleXMLRPCServer import SimpleXMLRPCServer
from random import randint
def TicTacServer(SimpleXMLRPCServer):
def __init__(self,host):
super(TicTacServer,self).__init__(host)
self.resetGame()
super(TicTacServer,self).register_function(self.addPlayer)
super(TicTacServer,self).register_function(self.getBoard)
super(TicTacServer,self).register_function(self.whoGoesFirst)
super(TicTacServer,self).register_function(self.insertMove)
super(TicTacServer,self).register_function(self.whosTurnIsIt)
super(TicTacServer,self).register_function(self.gameIsReady)
super(TicTacServer,self).register_function(self.resetGame)
super(TicTacServer,self).serve_forever()
所有这些功能都已声明并按预期工作。我不知道这是否可能,python 不会抛出任何错误,但我无法使用它连接到它
xmlrpclib.ServerProxy
这是代理服务器的代码:
from xmlrpclib import ServerProxy
class TicTacClient(ServerProxy):
def __init__(self,host):
ServerProxy.__init__(self,host)
self.board = self.getBoard()
这是我得到的错误
Traceback (most recent call last):
File "tictacClient.py", line 77, in <module>
client = TicTacClient('http://localhost:8081')
File "tictacClient.py", line 7, in __init__
self.board = self.getBoard()
File "C:\Python27\lib\xmlrpclib.py", line 1224, in __call__
return self.__send(self.__name, args)
File "C:\Python27\lib\xmlrpclib.py", line 1578, in __request
verbose=self.__verbose
File "C:\Python27\lib\xmlrpclib.py", line 1264, in request
return self.single_request(host, handler, request_body, verbose)
File "C:\Python27\lib\xmlrpclib.py", line 1292, in single_request
self.send_content(h, request_body)
File "C:\Python27\lib\xmlrpclib.py", line 1439, in send_content
connection.endheaders(request_body)
File "C:\Python27\lib\httplib.py", line 954, in endheaders
self._send_output(message_body)
File "C:\Python27\lib\httplib.py", line 814, in _send_output
self.send(msg)
File "C:\Python27\lib\httplib.py", line 776, in send
self.connect()
File "C:\Python27\lib\httplib.py", line 757, in connect
self.timeout, self.source_address)
File "C:\Python27\lib\socket.py", line 571, in create_connection
raise err
socket.error: [Errno 10061] No connection could be made because the target machine actively refused it