我是Apache Thrift的新手,并在Apache此处提供的玩具Delphi客户端服务器示例中玩耍:https://thrift.apache.org/tutorial/delphi
我们对名称以及端口和IP的设置方式进行了一些小的更改,但在其他方面基本相同。
在服务器中,我们有以下代码:
PORT := StrToInt(ParamStr(1));
handler := TPhraseGeneratorHandler.Create;
processor := TPhraseGenerator.TProcessorImpl.Create( handler);
transport := TServerSocketImpl.Create( PORT);
server := TSimpleServer.Create( processor, transport);
WriteLn( 'Starting the server on port ' + PORT.ToString + '...');
server.Serve();
在client中,我们有以下代码:
var transport : ITransport;
protocol : IProtocol;
client : TPhraseGenerator.Iface;
phraseRequest : IPhraseRequest;
// Let the user pass in the parameters for host and port
HOST : String;
PORT : Integer;
begin
try
// Open a connection to the server using the host and port supplied by the user
HOST := ParamStr(1);
PORT := StrToInt(ParamStr(2));
WriteLn('Openning a connection to the server: ' + HOST + ' on port: ' + PORT.ToString);
transport := TSocketImpl.Create( HOST, PORT, 10000); // specifically add a timeout as our test server deliberately goes to sleep for 5000ms
protocol := TBinaryProtocolImpl.Create( transport);
client := TPhraseGenerator.TClient.Create( protocol);
transport.Open;
如果我们在同一台计算机上打开客户端和服务器并使用'localhost',则可以使它们进行通信。
但是,如果我们在不同的计算机上打开它们并指定服务器的ipv4地址,则无法。
使用netstat,我们得到以下信息:
D:\Temp>netstat -ano | findstr 9090
TCP [::]:9090 [::]:0 LISTENING 15368
我认为这表明服务器仅在ipv6上进行监听。
问:我正确吗?如果可以的话,如何让它在ipv4上收听?