0

我们有一个通过 GAE 的图像服务提供图像的 java 应用程序。在 Linux 机器下用 eclipse 测试它很完美。但是在 Windows 机器 (Vista) 中测试完全相同的代码时,在引入图像时会失败。图片网址如下:

http://0.0.0.0:8888/_ah/img/encoded_gs_key:cHJvZmlsZXBpY3R1cmVzLzVVTkhjc1IybjktQTlrckdiZWZfTkE

我认为这与 0.0.0.0 地址有关,因为 Linux 将其解析为 127.0.0.1 但 Windows 甚至无法对其进行 ping 操作。有没有办法让 0.0.0.0 在 Windows 下工作?有什么办法可以改变GAE开发模式用来解析图片的0.0.0.0地址吗?

4

2 回答 2

4

我认为在这种情况下,Linux 做错了——我认为它试图通过将 0.0.0.0 路由到 127.0.0.1 来帮助工作,但实际上 0.0.0.0 是一个不可路由的地址并且 Windows 没有正确路由它。

见这里:http ://en.wikipedia.org/wiki/0.0.0.0

于 2014-01-11T02:04:48.100 回答
1

Short answer: I agree with Eight-Bit Guru. The fact that it works on Linux is probably just luck. (Although I'm sure the Linux networking guys would claim that Windows has it all wrong, but I digress).

I hit a similar issue porting some code from Linux to Windows once. My main thread would send an empty UDP packet to the listening address of the socket blocked on a recvfrom call on another thread. The thread waking up on the blocking recvfrom() call would notice the exit condition and promptly return.

The code on Linux worked. The main thread would call getsockname to get the local listen address of the socket and send a packet to it. And it just kind of worked when the socket was binded on INADDR_ANY (which means "all adapters", but is encoded as 0.0.0.0). Sending to 0.0.0.0 would reach the listening socket.

But this code path bombed on the port to Windows. The fix was to just detect when the listen address was 0.0.0.0 and switch it to send to 127.0.0.1 (localhost). And all was well.

So if fixing the code that generates the URL doesn't work, here's two solutions I thought about:

1. Add a route to the routing table (doesn't work)

Now I got to thinking if it was possible to just add a route to the route table. From the cmd line:

route add 0.0.0.0 MASK 255.255.255.255 10.120.30.194

That actually successfully adds a route to the table...

But alas, it didn't seem to work like I thought it would....

2. Run a proxy server

I think this might work for local debugging. You could run Fiddler along with your code. Implement a script/rule in Fiddler that will convert 0.0.0.0 to 127.0.0.1.

You didn't say what was doing the download. If it's a browser, then something like GreaseMonkey might be your friend.

于 2014-01-11T02:51:24.250 回答