delphi - (我认为)Thrift 服务器只监听 ipv6
问题描述
我是 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();
在客户端中,我们有以下代码:
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 上收听?
解决方案
我会说你是 100% 正确的。
相关部分来自CreateSocket()
:
// Pick the ipv6 address first since ipv4 addresses can be mapped
// into ipv6 space.
Res := Result.Res;
while Assigned(Res) do begin
if (Res^.ai_family = AF_INET6) or (not Assigned(Res^.ai_next)) then
Break;
Res := Res^.ai_next;
end;
FSocket := Winapi.Winsock2.socket(Res^.ai_family, Res^.ai_socktype, Res^.ai_protocol);
推荐阅读
- python - 如何通过python 3中的给定点绘制直方图
- sorting - 维度层次结构中的嵌套排序 (Tableau)
- python - Pyomo:最小化向量中的最大值
- bash - 将读取的光标返回到文件的开头
- c# - 有没有办法查看 DynamicMethod 生成的 x86 汇编代码?
- arrays - 使用数组中的两个文本字段填充组合框
- javascript - API puller 中的代码块,我不知道发生了什么
- python - Sqlalchemy:将 pandas 数据框中的新行添加到 mysql 表中,如果它们不存在于表中
- java - 调试 Java Swing App 导致计算机死机
- java - 无法调用 AOP 是建议