English 中文(简体)
B. 拟订甲状腺素方案的必要性建议
原标题:Need suggestions for android socket programming

We are developing an android app that send and receives text messages via wifi. We use TCP sockets for this communication (ip address and random port) but the problem is that if i dont allow these port numbers from my router s "port forwarding section", messages couldnt be sent. Are there any way to get rid of this problem?

问题回答

您可以随机从选定范围内抽取港口,然后在您的航道上走:

int port = (Math.abs(random.nextInt())) % 3000 + 1024;

这样我就产生了随机编号1024和2999。 或者只是一个固定港口。

If both clients are behind different restrictive firewalls, you should look into holepunching, where both clients open a connection with a third server, then the third server predicts the port opened on the NAT: NAT traversal with Java, https://stackoverflow.com/questions/917385/nat-traversal-with-java/. Note that this is typically needed for P2P applications (i.e., client to client) as you describe here. Yes, it s horribly complex and nasty :(

你也许会更好地利用亚马孙云层服务等一些东西,利用一种以推力为基础的机制,向另一方通报信息接收,或许利用长期污染吉大港山区。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签