gomobile socket permissions

118 views
Skip to first unread message

Dan Ballard

unread,
Aug 15, 2017, 11:58:21 AM8/15/17
to golang-nuts
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Socket socket = new Socket("127.0.0.1", 5051);

Works, no error. When I then:

GoRicochetMobile.echoBot(privateKey);

I get:

08-15 08:24:27.441 26959-26959/? I/GoLog: error setting up onion service: dial tcp4 127.0.0.1:9051: getsockopt: connection refused

Has any one had anyluck getting go code to make network connections on Android?

Elias Naur

unread,
Aug 15, 2017, 1:02:03 PM8/15/17
to golang-nuts
I've only had problems when I forgot to ask for android.permission.INTERNET whic I assume you have. Can you post a more complete program that demonstrates the problem?

 - elias

Dan Ballard

unread,
Aug 16, 2017, 10:54:58 AM8/16/17
to golang-nuts
Manifest
https://github.com/dballard/AndroidOD/blob/master/app/src/main/AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 
package="im.ricochet.androidod">

 
<uses-permission android:name="android.permission.INTERNET" />
 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Connect Activity
https://github.com/dballard/AndroidOD/blob/master/app/src/main/java/im/ricochet/androidod/ConnectActivity.java

Where the previous snippets are from setting the policy, opening a socket in java and calling go

The Go code it calls is a simple wrapper:
https://github.com/dballard/goRicochetMobile/blob/master/goRicochetMobile.go

of
https://github.com/s-rah/go-ricochet

The actual connection should be happening in
https://github.com/s-rah/go-ricochet/blob/master/vendor/github.com/yawning/bulb/conn.go
Dial() at line 214

Elias Naur

unread,
Aug 16, 2017, 11:40:52 AM8/16/17
to golang-nuts
Hi,

Have you tried the golang.org/x/mobile/example/network example? It's a "pure" Go app that doesn't use Java bindings, but its network access properties should be the same.

If that works, you could modify golang.org/x/mobile/example/bind to introduce a simple http.Get (or net.Dial) and see if that works. If so, you have a basis for bisection.

 - elias

Dan Ballard

unread,
Aug 29, 2017, 2:37:22 PM8/29/17
to Elias Naur, golang-nuts
Hey thanks! I got it to work!

--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/lMZy22tlk6Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages