选择在Android传出TCP / IP端口 [英] Select outgoing TCP/IP port on Android

查看:133
本文介绍了选择在Android传出TCP / IP端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法选择连接的时候,比如我用的出端口,一个web服务?我将致力于一个Android设备上,这样理想的东西基于Java的将是最容易的。

Is there way select the outgoing port that I use when connecting, for example, to a web-service? I'll be working on a Android device so ideally something Java based would be easiest.

推荐答案

您可以使用的 Socket.bind()如果您要选择本地地址和端口,否则将被绑定到一个本地接口和第一个可用的临时端口。

You can use Socket.bind() if you want to select local address and port, otherwise it is bound to one of local interfaces and the first available ephemeral port.

您可能不得不虽然写你自己的HTTP UA的实现,如果您的HTTP客户端不支持绑定并不允许提供自己的插座

You may have to write your own HTTP UA implementation though if your HTTP client doesn't support bind and doesn't allow to provide your own socket

这篇关于选择在Android传出TCP / IP端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆