- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在开发一个项目,我的 android 应用程序应该充当其他 android 客户端的服务器。我正在使用 Eneter messaging framework它使用套接字和谷歌 Protobuf .. 在 wifi 上一切都像一个魅力但是一旦我切换到 3g 网络(尝试使用手机的 3g 公共(public) ip 地址和端口 80/81 启动服务器)我收到以下错误:EACCES(权限被拒绝)
E/EneterMessaging: ~24216 eneter.messaging.messagingsystems.tcpmessagingsystem.internal.TcpListenerProvider.startListening TcpListenerProvider failed to start listening.
Exception:
java.net.BindException: bind failed: EACCES (Permission denied)
libcore.io.IoBridge.bind(IoBridge.java:99)
java.net.PlainSocketImpl.bind(PlainSocketImpl.java:132)
java.net.ServerSocket.bind(ServerSocket.java:335)
eneter.messaging.messagingsystems.tcpmessagingsystem.NoneSecurityServerFactory.createServerSocket(NoneSecurityServerFactory.java:51)
eneter.messaging.messagingsystems.tcpmessagingsystem.internal.TcpListenerProvider.startListening(TcpListenerProvider.java:123)
eneter.messaging.messagingsystems.tcpmessagingsystem.TcpInputConnector.startListening(TcpInputConnector.java:134)
eneter.messaging.messagingsystems.simplemessagingsystembase.internal.DefaultDuplexInputChannel.startListening(DefaultDuplexInputChannel.java:96)
eneter.messaging.infrastructure.attachable.internal.AttachableDuplexInputChannelBase.attachDuplexInputChannel(AttachableDuplexInputChannelBase.java:40)
com.inactivity.magamine.teatime.services.TCPService.StartServer(TCPService.java:261)
com.inactivity.magamine.teatime.services.TCPService$6.run(TCPService.java:279)
java.lang.Thread.run(Thread.java:818)
我的 list 中有这些权限:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
这是启动服务器的代码:
public void StartServer() throws Exception
{
// Create sender sending MyRequest and as a response receiving MyResponse
// Instantiate Protocol Buffer based serializer.
ISerializer aSerializer = new ProtoBufSerializer();
// Create sender sending MyRequest and as a response receiving MyResponse
// The sender will use Protocol Buffers to serialize/deserialize messages.
IDuplexTypedMessagesFactory aRecieverFactory = new DuplexTypedMessagesFactory(aSerializer);
myReceiver = aRecieverFactory.createDuplexTypedMessageReceiver(MessageDeclarations.MyMsg.class, MessageDeclarations.MyMsg.class);
myReceiver.messageReceived().subscribe(myOnRequestHandler);
if(aMessaging == null)aMessaging = new TcpMessagingSystemFactory();
IDuplexInputChannel anInputChannel
= aMessaging.createDuplexInputChannel(Service_URL);//Service_URL = "tcp://xxx.xxx.x.xx:80/ with public ip adress
// Attach the output channel to the sender and be able to send
// messages and receive responses.
myReceiver.attachDuplexInputChannel(anInputChannel);
isConnected = true;
showNotification("Server Started","url: "+Service_URL,Color.GREEN);
}
异常发生在
myReceiver.attachDuplexInputChannel(anInputChannel);
这就是 Eneter 启动套接字服务器的地方。
EDIT: From this I found that to bind on ports < 1024 you need root privileges. So I tried ports like 1025, 8080, 8081 , I now get this exception instead: Cannot assign requested address, is it that I cant use 3G network public ip adress to start a socket server or am I missing something ?
E/EneterMessaging: ~25710 eneter.messaging.messagingsystems.simplemessagingsystembase.internal.DefaultDuplexInputChannel.startListening DefaultDuplexInputChannel 'tcp://105.66.131.38:8080/' failed to start listening.
Exception:
java.net.BindException: bind failed: EADDRNOTAVAIL (Cannot assign requested address)
libcore.io.IoBridge.bind(IoBridge.java:99)
java.net.PlainSocketImpl.bind(PlainSocketImpl.java:132)
java.net.ServerSocket.bind(ServerSocket.java:335)
eneter.messaging.messagingsystems.tcpmessagingsystem.NoneSecurityServerFactory.createServerSocket(NoneSecurityServerFactory.java:51)
eneter.messaging.messagingsystems.tcpmessagingsystem.internal.TcpListenerProvider.startListening(TcpListenerProvider.java:123)
eneter.messaging.messagingsystems.tcpmessagingsystem.TcpInputConnector.startListening(TcpInputConnector.java:134)
eneter.messaging.messagingsystems.simplemessagingsystembase.internal.DefaultDuplexInputChannel.startListening(DefaultDuplexInputChannel.java:96)
eneter.messaging.infrastructure.attachable.internal.AttachableDuplexInputChannelBase.attachDuplexInputChannel(AttachableDuplexInputChannelBase.java:40)
com.inactivity.magamine.teatime.services.TCPService.StartServer(TCPService.java:261)
com.inactivity.magamine.teatime.services.TCPService$6.run(TCPService.java:279)
java.lang.Thread.run(Thread.java:818)
我会感谢你的帮助。
亲切
最佳答案
原始问题的答案
端口分配失败,因为如您所述,80 是特权端口。
更新问题的答案
IP 地址分配失败,因为事实证明,您的代码中有错误的 IP 地址。一旦您关闭 WiFi 网络(大概)以进入移动网络,您使用的地址就会从系统中删除,并且您的无线运营商会为您分配一个不同的地址。使用 0.0.0.0 本质上告诉您的服务器库,“我想在所有接口(interface)上监听”。 (另一种选择是找出您的移动 IP 地址,然后使用它。)但这将我们带到了最后一个问题:
对您当前问题的评论
无法连接的原因可能有很多。我怀疑可能是 NAT ,如 this question 中所述.长话短说,很少有应用程序(如果有的话)使用您选择的架构(在连接到移动网络的用户手机上运行服务器)。由于 NAT,手机几乎总是必须“拨出”才能形成连接(在移动网络上)。而且您的服务器没有拨出;它在听。
只要您不跨越 NAT 边界,这些限制就不适用于您的本地 WiFi 网络。
要解决这个问题,您可能需要了解网络架构,并接受一些网络调试方面的培训。像 Wireshark 这样的捕获工具是一个很大的帮助。
如果您在这方面需要更多帮助,而 SO 上的其他答案都没有帮助您,那么最好开始一个新问题。
关于java - 使用 Eneter Messaging 和 Protocol Buffers 在 3g 网络上的端口 80 上启动 tcp 服务器的权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52823670/
我是 ZMQ 的新手。我发现 ZMQ 套接字实现比 winsock 简单得多。但我怀疑 “使用 ZMQ TCP 套接字创建的客户端可以与传统的 TCP 服务器通信吗?” 换句话说我的 ZMQ 客户端可
我想使用 TCP 协议(protocol) 将数据发送到 Logstash。为了发送数据,我正在使用 Node-RED。一个简单的配置如下所示: 在 Logstash 文件夹中,我创建了一个名为 no
当我尝试更改窗口缩放选项时,作为 root,我可以通过在 /proc/sys/net/中执行 net.ipv4.tcp_mem=16777000 来更改值。如果我必须更改这 100 个系统,那将需要大
明天做一些练习题,这道做不出来 TCP 服务器连接 TCP 客户端进行通信所需的最小套接字端口数是多少? 肯定只有两个吧?一个用于服务器,一个用于客户端,但这似乎是显而易见的。我的伙伴们认为 TCP
考虑一个存在一个服务器和多个客户端的场景。每个客户端创建 TCP 连接以与服务器交互。 TCP alive的三种用法: 服务器端保活:服务器发送 TCP 保活以确保客户端处于事件状态。如果客户端死了,
TCP TAHOE 和 TCP RENO 有什么区别。 我想知道的是关于 3-dup-ack 和超时的行为? SST 发生了什么变化? 谢谢! 最佳答案 TCP Tahoe 和 Reno 是处理 TC
大家早上好。我一直在阅读(其中大部分在堆栈溢出中)关于如何进行安全密码身份验证(散列 n 次,使用盐等)但我怀疑我将如何在我的 TCP 客户端中实际实现它-服务器架构。 我已经实现并测试了我需要的方法
在遍历 RFC793 时,我开始知道应该以这种方式选择初始序列号段重叠被阻止。 有人能解释一下如果发生重叠,重复段将如何影响 TCP? 最佳答案 不同的操作系统有不同的行为。参见 http://ins
你能举例说明一下tcp/ip中nagle算法的概念吗? 最佳答案 我认为Wikipedia在开头的段落中做得很好。 Nagle's document, Congestion Control in IP
似乎最大 TCP 接收窗口大小为 1GB(使用缩放时)。因此,仍然可以用一个连接填充 100Gb 管道的最大 RTT 是 40ms(因为 2 * 40E-3 * 100E9/8 = 1GB)。这会将这
考虑在两个 TCP 端点之间建立的 TCP 连接,其中一个调用: 关闭():此处,不允许进一步读取或写入。 关机(fd,SHUT_WR):这会将全双工连接转换为单工连接,其中调用 SHUT_WR 的端
我是在 Lua 中编写解析器的新手,我有两个简短的问题。我有一个包含 TCP 选项的数据包,如 MSS、TCP SACK、时间戳、NOP、窗口比例、未知。我基本上是在尝试剖析 TCP 选项字段中的未知
TCP 是否不负责通过在传输过程中发生丢失等情况时采取任何可能必要的措施来确保通过网络完整地发送流? 它做的不对吗? 为什么更高的应用层协议(protocol)及其应用程序仍然执行校验和? 最佳答案
考虑使用 10 Mbps 链路的单个 TCP (Reno) 连接。假设此链路不缓冲数据并且接收方的接收缓冲区比拥塞窗口大得多。设每个 TCP 段的大小为 1500 字节,发送方和接收方之间连接的双向传
考虑这样一个场景,有client-a和server-b。 server-b 禁用了 TCP keepalive。 server-b 没有任何应用程序逻辑来检查 TCP 连接是否打开。 client-a
我正在尝试用 Rust 编写回显服务器。 use std::net::{TcpStream, TcpListener}; use std::io::prelude::*; fn main() {
听说对于TCP连接,服务器会监听一个端口,并使用另一个端口发送数据。 例如,Web 服务器监听端口 80。每当客户端连接到它时,该服务器将使用另一个端口(比如 9999)向客户端发送数据(Web 内容
我试图了解带有标记 PSH 和标记 URG 的 TCP 段之间的区别。我阅读了 RFC,但仍然无法理解,其中一个在将数据发送到进程之前缓冲数据而另一个没有吗? 最佳答案 它们是两种截然不同的机制。 #
有第三方服务公开 TCP 服务器,我的 Node 服务器(TCP 客户端)应使用 tls Node 模块与其建立 TCP 连接。作为 TCP 客户端, Node 服务器同时也是 HTTP 服务器,它应
我正在发送一些 TCP SYN 数据包以获得 TCP RST 的返回。为了识别每个探测器,我在 TCP 序列字段中包含一个计数器。我注意到以下几点: 当SYN probe中的sequence numb
我是一名优秀的程序员,十分优秀!