問題
我試圖使用SocketServer附帶Python的,但我在握手階段的一些問題。只要使用localhost或127.0.0.1,握手就可以正常工作。但是,當我把我的eth0卡的IP,它只是不會握手。我測試的官方示例代碼found here:Python的SocketServer的won''t握手
import SocketServer
class MyTCPHandler(SocketServer.BaseRequestHandler):
def handle(self):
self.data = self.request.recv(1024).strip()
print "{} wrote:".format(self.client_address[0])
print self.data
self.request.sendall(self.data.upper())
if __name__ == "__main__":
HOST, PORT = "localhost", 9999
server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler)
server.serve_forever()
終端片段:
[email protected]:~$ netcat 10.2.203.26 9999
[email protected]:~$
[email protected]:~$ netcat localhost 9999
test
正如您在摘要中看到,嘗試連接到10.2.293.26
這是我的網卡不工作的IP。只要我嘗試連接到localhost
,它工作正常!
在Wireshark上,從客戶端向服務器發送第一個SYN(在初始握手階段)後,我得到一個[RST, ACK]
。
工作正常,我的第一個猜測是,這是重新連接的路由器。然而事實並非如此,因爲我可以telnet
罰款:
端子1:
[email protected]:~/tmp/test$ netcat -l 9999
(waiting)
test
2號航站樓:
[email protected]:~$ netcat 10.2.203.26 9999
test
只是一個快速建議,您是否正確設置了端口轉發? – redspidermkv 2014-11-25 11:23:21
@redspidermkv那麼'telneting'不會工作,如果這是問題.. – Pithikos 2014-11-25 11:36:53