Closed httuan250591 closed 2 years ago
Probably your server is not configured for WebSocket connection Please update your config file
websocket { port: 8080 no_tls: true }
yes there is an issue while we enable ws on server with token auth when i add in token in opts ex. //. 'token': 'dfvndofvndvdnvodnveo', this give me error of Status.ERROR ('Authorization Violation') but same code working fine on node js client with token auth.
Kindly fix it asap.
@nileshsoni97 Did you follow my server installation in the README file?
https://github.com/dgofman/nats_client/blob/master/README.md
Yes here is my code
` final conn = await Nats.connect(
opts: {
'servers': 'ws://111.111.111.111:111',
'reconnectTimeWait': 2000, // 2s
'pingInterval': 10000, //10s
'reconnect': true,
'maxReconnectAttempts': 0,
//'token':'token',
// 'user': "rs",
// 'pass': "dmsodknoeirnfe "
},
debug: false,
authenticator: JwtAuthenticator.create("token"),
statusCallback: (status, error) async {
if (error != null) {
print('natsClient : ERROR $error');
}
if (status == Status.PING_TIMER) {
print("natsClient : ${status.toString()}");
} else if (status == Status.CONNECT) {
print("natsClient : ${status.toString()}");
}
});
conn.subscribe('hello', (Result result) {
print("natsClient : ${utf8.decode(result.data)}");
});`
but still getting same error Status.ERROR ('Authorization Violation')
Server code :
`port: 111 # Listening port for client connection
server_name : "nats-default"
http: localhost:110 # For Monitering
#tls: {
# cert_file: "C:/certificate/cert.cer"
# key_file: "C:/certificate/cert.key"
# ca_file: "C:/certificate/cert.pem"
# insecure : true
#}
# Log options
debug: false
trace: false
logtime: true
log_file: "C:/tmp/gnatsd.log"
authorization: {
token:token
timeout: 3
# users: [
# {user: r, password : dmsodknoeirnfe},
# {user: w, password : sndijnviuneiunre}]
}
websocket {
# host: "0.0.0.0"
port: 11112
no_tls: true
authorization {
token:token
timeout: 3
# users: [
# {user: r, password : dmsodknoeirnfe},
# {user: w, password : sndijnviuneiunre}
#]
}
allowed_origins [
"*"
]
}
jetstream {
store_dir=nats
// 1GB
max_memory_store: 1073741824
// 1GB
max_file_store: 1073741824
}`
But now i moved to user, pass auth and it's best with permission so now no needs of token auth. Thanks for your contribution to Nats i appreciate your work.
What kind of IP address are you using '111.111.111.111:111' (5 pairs)
This is random i just replaced original values.
last one is port :111 only 4 pairs
JwtAuthenticator.create("token"), == CREATE USER TOKEN - nsc add user --bearer --name
"--bearer " must be set
Thanks for your help but now i used user-pass auth and that is awesome one again i appreciate you.
Client code:
Error log: