0
我正在嘗試做TCP打孔在德爾福。我只有一個端口打開 - 10000(用於測試目的)。德爾福:TCP打孔
這裏是我的代碼片段(full source code):在端口10000
IdTCPServerRetr.Active:=True
procedure TFormMain.btnEnableRedirectClick(Sender: TObject); begin IdTCPServerRetr.Active:=True; end; procedure TFormMain.btnConnectToClientClick(Sender: TObject); begin if IdTCPClientRemote.Port = 0 then ShowMessage('Wait for connection to redirect server...') else begin IdTCPClientRemote.Host:=MyIP; IdTCPClientRemote.Connect; ShowMessage('S U C C E S S'); end; end; procedure TFormMain.btnConnectClick(Sender: TObject); begin IdTCPClientLocal.Host:=MyIP; IdTCPClientLocal.Connect; ShowMessage('Connected to redirect server!'); end; procedure TFormMain.btnListenClick(Sender: TObject); begin IdTCPServerLocal.DefaultPort:=IdTCPClientLocal.Socket.Binding.Port; IdTCPServerLocal.Active:=True; ShowMessage('Local server started!'); end; procedure TFormMain.IdTCPServerRetrExecute(AContext: TIdContext); begin IdTCPClientRemote.Port:=AContext.Connection.Socket.Binding.PeerPort; end;
首先,我運行遠程服務器(重定向);
之後,我連接到重定向服務器(端口10000)並使用與客戶端相同的端口創建本地服務器。
IdTCPClientLocal.Connect; IdTCPServerLocal.DefaultPort:= IdTCPClientLocal.Socket.Binding.Port; IdTCPServerLocal.Active:=True;
(客戶端和服務器有一個reusesocket = rsTrue)
在那之後,我嘗試連接到客戶端,其內部端口上,但我得到的錯誤「連接超時 」。
我認爲問題在於遠程客戶端無法找到要連接的服務器,因爲客戶端已經與重定向服務器建立了連接。
我不得不閱讀關於TCP打孔的知識,因爲我不知道它是什麼。如果我理解正確的話,它會指望雙方都嘗試打開一個連接,並讓套接字**都發送一個SYN數據包**並期待可選的SYN-ACK,我不確定Indy是否支持爲了那個原因。 –