Java Server不接收来自特定Internet连接的文件。任何想法?

时间:2022-02-27 23:56:59

I have built an android app which takes a pictures and send it to a server running on my pc using Java sockets. The Server receives the picture successfully when I send it from my android mobile using the same wifi network with the one that pc-server uses but it doesn't receive the image when I am sending it from another place using different network or when I use my mobile phone internet megabytes. It seems like image get lost on the way to the server because the android app runs properly and never get into catch{} code to throw an exception. Any idea????

我已经构建了一个Android应用程序,它使用Java套接字拍摄照片并将其发送到我的电脑上运行的服务器。当我从我的Android手机发送它时使用与pc-server使用的相同的wifi网络但是当我从另一个地方使用不同的网络发送它时或者当我使用它时它没有收到图像时,服务器成功接收图片我的手机上网兆字节。看起来像图像在去服务器的路上丢失了,因为Android应用程序正常运行并且永远不会进入catch {}代码来抛出异常。任何的想法????

2 个解决方案

#1


Your pc server is using a WiFi router to connect to the Internet. That router is acting like a firewall that you need to disable so you can access from outside your WiFi network.

您的PC服务器正在使用WiFi路由器连接到Internet。该路由器的作用类似于您需要禁用的防火墙,因此您可以从WiFi网络外部进行访问。

The best way is to open some port and forward it to your server:

最好的方法是打开一些端口并将其转发到您的服务器:

http://www.wikihow.com/Set-Up-Port-Forwarding-on-a-Router

Then you could access from the outside. Remember to use the your external IP address and not the local one.

然后你可以从外面访问。请记住使用您的外部IP地址而不是本地IP地址。

http://whatismyipaddress.com/es/mi-ip

#2


I'm not sure if this will solve your problem. but I had that problem before. in my case, just like you, my connection worked on wifi, but never on my 3g mobile carrier internet. it was a long time ago, so I don't remember exactly why, but adding "Content-Type", "charset=utf-8" to my headers solved my problem.

我不确定这是否能解决你的问题。但我以前遇到过这个问题。在我的情况下,就像你一样,我的连接工作在wifi,但从来没有在我的3G移动运营商互联网上。很久以前,所以我不记得原因,但在我的标题中添加“Content-Type”,“charset = utf-8”解决了我的问题。

i was using volley, so basically my headers looked like this:

我正在使用凌空,所以基本上我的标题看起来像这样:

 @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            HashMap<String, String> headers = new HashMap<String, String>();
            headers.put("Content-Type", "application/json; charset=utf-8");
            return headers;
        }

for some reason, some specific carriers require to add utf encoding to the headers.

由于某种原因,某些特定的运营商需要在标头中添加utf编码。

well, at least that was my own case. give it a try :)

好吧,至少那是我自己的情况。试试看 :)

#1


Your pc server is using a WiFi router to connect to the Internet. That router is acting like a firewall that you need to disable so you can access from outside your WiFi network.

您的PC服务器正在使用WiFi路由器连接到Internet。该路由器的作用类似于您需要禁用的防火墙,因此您可以从WiFi网络外部进行访问。

The best way is to open some port and forward it to your server:

最好的方法是打开一些端口并将其转发到您的服务器:

http://www.wikihow.com/Set-Up-Port-Forwarding-on-a-Router

Then you could access from the outside. Remember to use the your external IP address and not the local one.

然后你可以从外面访问。请记住使用您的外部IP地址而不是本地IP地址。

http://whatismyipaddress.com/es/mi-ip

#2


I'm not sure if this will solve your problem. but I had that problem before. in my case, just like you, my connection worked on wifi, but never on my 3g mobile carrier internet. it was a long time ago, so I don't remember exactly why, but adding "Content-Type", "charset=utf-8" to my headers solved my problem.

我不确定这是否能解决你的问题。但我以前遇到过这个问题。在我的情况下,就像你一样,我的连接工作在wifi,但从来没有在我的3G移动运营商互联网上。很久以前,所以我不记得原因,但在我的标题中添加“Content-Type”,“charset = utf-8”解决了我的问题。

i was using volley, so basically my headers looked like this:

我正在使用凌空,所以基本上我的标题看起来像这样:

 @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            HashMap<String, String> headers = new HashMap<String, String>();
            headers.put("Content-Type", "application/json; charset=utf-8");
            return headers;
        }

for some reason, some specific carriers require to add utf encoding to the headers.

由于某种原因,某些特定的运营商需要在标头中添加utf编码。

well, at least that was my own case. give it a try :)

好吧,至少那是我自己的情况。试试看 :)