我正在使用这个android git REPO https://github.com/tylerjroach/eventsource-android 我实现了方法
public void onConnects() {
Thread eventThread = new Thread(new Runnable() {
@Override
public void run() {
try {
eventSource = new EventSource(URI.create(myApiUrl), new SSEHandler(), true);
eventSource.connect();
} catch(Exception e) {
e.printStackTrace();
}
}
});
eventThread.start();
}
但我不得不改变eventsource.connect();从私人到公共,让这个工作。然后,我放入我的Api Url和参数,它失败了。这是怎么回事?
这是我的堆栈跟踪
02-18 02:16:37.315 18398-18411 / com.athena.myapplication W / System.err:org.jboss.netty.channel.ChannelException:无法打开套接字。 02-18 02:16:37.315 18398-18411 / com.athena.myapplication W / System.err:at org.jboss.netty.channel.socket.nio.NioClientSocketChannel.newSocket(NioClientSocketChannel.java:49) 02-18 02:16:37.315 18398-18411 / com.athena.myapplication W / System.err:at org.jboss.netty.channel.socket.nio.NioClientSocketChannel。(NioClientSocketChannel.java:83) 02-18 02:16:37.315 18398-18411 / com.athena.myapplication W / System.err:at org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory.newChannel(NioClientSocketChannelFactory.java:167) 02-18 02:16:37.315 18398-18411 / com.athena.myapplication W / System.err:at org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory.newChannel(NioClientSocketChannelFactory.java:86) 02-18 02:16:37.315 18398-18411 / com.athena.myapplication W / System.err:at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:218) 02-18 02:16:37.315 18398-18411 / com.athena.myapplication W / System.err:at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:188) 02-18 02:16:37.315 18398-18411 / com.athena.myapplication W / System.err:at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:159) 02-18 02:16:37.315 18398-18411 / com.athena.myapplication W / System.err:at tylerjroach.com.eventsource_android.EventSource.connect(EventSource.java:149) 02-18 02:16:37.315 18398-18411 / com.athena.myapplication W / System.err:at com.athena.myapplication.MainActivity $ 2.run(MainActivity.java:63) 02-18 02:16:37.315 18398-18411 / com.athena.myapplication W / System.err:at java.lang.Thread.run(Thread.java:841) 02-18 02:16:37.315 18398-18411 / com.athena.myapplication W / System.err:引起:java.net.SocketException:套接字失败:EACCES(权限被拒绝) 02-18 02:16:37.315 18398-18411 / com.athena.myapplication W / System.err:at libcore.io.IoBridge.socket(IoBridge.java:576) 02-18 02:16:37.315 18398-18411 / com.athena.myapplication W / System.err:at java.nio.SocketChannelImpl。(SocketChannelImpl.java:102) 02-18 02:16:37.315 18398-18411 / com.athena.myapplication W / System.err:at java.nio.SocketChannelImpl。(SocketChannelImpl.java:93) 02-18 02:16:37.315 18398-18411 / com.athena.myapplication W / System.err:at java.nio.SelectorProviderImpl.openSocketChannel(SelectorProviderImpl.java:49) 02-18 02:16:37.315 18398-18411 / com.athena.myapplication W / System.err:at java.nio.channels.SocketChannel.open(SocketChannel.java:81) 02-18 02:16:37.315 18398-18411 / com.athena.myapplication W / System.err:at org.jboss.netty.channel.socket.nio.NioClientSocketChannel.newSocket(NioClientSocketChannel.java:47) 02-18 02:16:37.315 18398-18411 / com.athena.myapplication W / System.err:... 9更多 02-18 02:16:37.315 18398-18411 / com.athena.myapplication W / System.err:引起:libcore.io.ErrnoException:套接字失败:EACCES(权限被拒绝) 02-18 02:16:37.325 18398-18411 / com.athena.myapplication W / System.err:at libcore.io.Posix.socket(Native Method) 02-18 02:16:37.325 18398-18411 / com.athena.myapplication W / System.err:at libcore.io.BlockGuardOs.socket(BlockGuardOs.java:181) 02-18 02:16:37.325 18398-18411 / com.athena.myapplication W / System.err:at libcore.io.IoBridge.socket(IoBridge.java:561) 02-18 02:16:37.325 18398-18411 / com.athena.myapplication W / System.err:... 14 more