gomobile build, the Paho mqtt client cannot connect to mqtt broker in APK - apk

I am working on a project where I need to use gomobile tool to create an Android app.
The sample code I have in Go is as below
var broker = "127.0.0.1"
//var broker = "broker.mqttdashboard.com"
var port = 1883
opts := mqtt.NewClientOptions()
opts.AddBroker(fmt.Sprintf("tcp://%s:%d", broker, port))
opts.SetClientID("go_mqtt_client")
opts.SetConnectionLostHandler(connectLostHandler) // define what to do when connection is lost
client := mqtt.NewClient(opts)
tokenClient := client.Connect()
if tokenClient.Wait() && tokenClient.Error() != nil {
panic(tokenClient.Error())
}
...
When I bind this code using "gomobile bind", generating the Golang plugin and calling them inside the android project there is no issue.
Connections is satisfied and I can verify the local mqtt broker (mosquitto) and the mqtt client app are communicating as well.
But when I generate the APK file using "gomobile build -target=android", the connect function generates and error.
To be able to test the logs i used a public broker instead of the local mqtt broker. I replaced the
var broker = "127.0.0.1"
by the HiveMQ public broker address (I have already validated the public broker functionality)
var broker = "broker.mqttdashboard.com"
It seems like there is an issue with connecting from mqtt client app to mqtt broker. Here is the exact error message I found in logs:
E/Go: panic: network Error : dial tcp: lookup
broker.mqttdashboard.com: No address associated with hostname
goroutine 11 [running]: E/GoLog: panic: network Error : dial tcp: lookup broker.mqttdashboard.com: No address associated with hostname
E/Go: main.starting()
This is generated by "panic(tokenClient.Error())" part in my code.
Any idea why the connection is not settled using "gomobile build", while it is working when I use "gomobile bind" ?

Here is how I could fix the issue.
I added the AndoridManifest.xml file to the same directory that the main go package is.
Added the following line in between the manifest tags (<manifest> )
<uses-permission android:name="android.permission.INTERNET">

Related

can't start solana validator node,can't connect

I have used SSR, and the viewer can access the node
get_cluster_shred_version failed: 108.160.170.41:8001, connection timed out
.....
[2022-05-07T01:25:37.984950553Z INFO solana_validator] Contacting 128.242.240.212:8001 to determine the validator's public IP address
....
Unable to determine the validator's public IP address
This error happens when it isn't possible for the software to figure out what its public ip address is for the gossip protocol at this line: https://github.com/solana-labs/solana/blob/8d0134e0fdede539cf8ab89ef0ce794f1d41f9dc/validator/src/main.rs#L2819
To be explicit, pass --gossip-host and --gossip-port, ie:
$ solana-validator <all of your previous args> --gossip-host YOUR_IP_HERE --gossip-port 8001
Note that you don't need to have your gossip port at 8001, but it's a convention.

Some problems on QUIC-GO example server

The situation is, I wanna establish a QUIC connection based on quic-go from local to ECS server. The related tests using localhost are done both on local and remote device. That is:
#local: .$QUIC-GO-PATH/example/client/main -insecure -keylog ssl.log -qlog trial.log -v https://127.0.0.1:6121/demo/tile
#local: .$QUIC-GO-PATH/example/main -qlog -tcp -v
These tests are completed.
Now is the problem,when I start local-remote connection an error occurred:
#remote: .$QUIC-GO-PATH/example/main -qlog -tcp -v
#local: .$QUIC-GO-PATH/example/client/main -insecure -keylog ssl.log -qlog trial.log -v https://$REMOTE_IPADDR:6121/demo/tile
timeout: no recent network activity
When I go through a wireshark examination, it seems like the CRYPTO handshake never finishes:
Wireshark
Also client Qlog file atteched here:
Qlog file
Codes are all the same with https://github.com/lucas-clemente/quic-go
Help!
This problem has been solved.
Code $QUIC-GO-PATH/example/main.go has binded the port as a default onto 127.0.0.1:6121, which led to the problem that the server cannot get reached by client outside, just get this on server running:
-bind 0.0.0.0:6121

JMeter - Listen to a port on a given IP

I want to run a jmeter test, which listens to a port on a given ip, and prints the messages which are being sent to that port. I have tried using this:
SocketAddress inetSocketAddress = new InetSocketAddress(InetAddress.getByName("<client ipAddress>"),<port number>);
def server = new ServerSocket();
server.bind(inetSocketAddress);
while(true) {
server.accept { socket ->
log.info('Someone is connected')
socket.withStreams { input, output ->
def line = input.newReader().readLine()
log.info('Received message: ' + line)
}
log.info("Connection processed")
}
}
But this is giving me error - "Cannot assign requested address: JVM_Bind
"
Is there any alternate way to approach this? Or what changes do i need to do for the current approach to work?
You copied and pasted this code from the right place and it should work just fine. Evidence:
as per the BindException documentation
Signals that an error occurred while attempting to bind a socket to a local address and port. Typically, the port is in use, or the requested local address could not be assigned.
So I can think of 2 options:
Your <client ipAddress> is not correct and cannot be resolved.
Something is already running on the <port number>, you cannot have 2 applications listening to the same port, the first one will be successful and another one will fail
More information:
Fixing java.net.BindException: Cannot assign requested address: JVM_Bind in Tomcat, Jetty
Apache Groovy - Why and How You Should Use It

How to connect to a Gremlin Websocket in Go?

I'm trying to connect to Gremlin which should be running on port 8182 ([INFO] GremlinServer$1 - Channel started at port 8182)
When I'm connecting to: ws://127.0.0.1:8182 I'm getting the response:
2017/11/03 17:20:04 ERROR: database with the name 'gremlin' gave an error when connecting: websocket: bad handshake.
The Gremlin server responds with:
[WARN] HttpGremlinEndpointHandler - Invalid request - responding with 400 Bad Request and no gremlin script supplied
I'm using Gorilla Websocket in Go to connect:
gremlinGrpcAddress := fmt.Sprintf("ws://%s:%d/", f.config.Host, f.config.Port)
var dialer *websocket.Dialer
clientConn, _, err := dialer.Dial(gremlinGrpcAddress, nil)
if err != nil {
return err
}
f.client = clientConn
UPDATE:
Connecting to echo.websocket.org works, so somehow it is something in the Gremlin server.
The answer lies in the config YAML file.
What is needed is the correct channelizer.
GOOD:
channelizer: org.apache.tinkerpop.gremlin.server.channel.WebSocketChannelizer
Connect to ws://localhost:8182/gremlin instead of ws://localhost:8182. There are several references to it in the Apache TinkerPop documentation and the go-gremlin README.

Cannot connect to amqp://user:**#ip-11-222-12-117:5672//: Couldn't log in: a socket error occurred

I am trying to scale airflow using celery and rabbitMq on EC2.
I am following following code:
http://site.clairvoyantsoft.com/setting-apache-airflow-cluster/
Following is code in master node.
sql_alchemy_conn = postgresql+psycopg2://user:gues#localhost:5432/airflow
executor = CeleryExecutor
broker_url = amqp://user:gues#ip-11-222-12-117:5672
celery_result_backend = db+postgresql://user:gues#localhost:5432/airflow
Following is code for salve node:
sql_alchemy_conn = postgresql+psycopg2://user:gues#ip-11-222-12-117:5432/airflow
executor = CeleryExecutor
broker_url = amqp://user:gues#ip-11-222-12-117:5672
celery_result_backend = db+postgresql://user:gues#localhost:5432/airflow
When I run airflow scheduler, it works fine. But on slave node I am getting following error:
[2017-05-23 21:47:44,385: ERROR/MainProcess] consumer: Cannot connect to amqp://user:**#ip-11-222-12-117:5672//: Couldn't log in: a socket error occurred.
Trying again in 2.00 seconds..
However I am able to see both nodes connected using rabbitMq on rabbitMQ UI.
What I am doing wrong?
Have you checked that the amqp server is allowed to listen to anything other than the loopback? Please check this answer: Can't access RabbitMQ web management interface after fresh install

Resources