In my ionic 4 application, I am using strophe.js to connect to Ejabbered server. In the application after status connected I am able to see chats successfully but after sometime it gets disconnected on its own and chats disappear without doing any thing.
In the logs,Strophe is disconnecting with following status:
EjabService [Connection] Unknown status received: and status is 10
Also on few devices, not able to see chats due to connection problem.
Ejabbered version installed: 20.03
Here is the code to connect to Ejabbered Server using Strophe.js:
/*Function
Connects the client from the Jabber server.
Parameters:
(String) jid - Jabber id.
(String) pass - Password.
Returns:
*/
login(jId, password, callback) {
try {
this.connection = new Strophe.Connection(this.BOSH_SERVICE, {
keepalive: true,
});
this.connection.connect(jId + "#" + this.host, password, (status) => {
this.onConnect(status, callback);
});
} catch (error) {
console.log(`error connecting to bosh service ${error}`);
}
}
/*Function
Connect XMPP.
Parameters:
Returns:
status - Status of connection.
*/
onConnect(status, callback) {
try {
var self = this;
switch (status) {
case Strophe.Status.CONNECTED:
this.logger.info(
`EjabService [Connection] Strophe is Connected with status ${status}`);
callback();
self.connection.addHandler(
(msg) => {
return self.onMessage(msg);
},
null,
"message",
null,
null,
null
);
self.connection.addHandler(
(ping) => {
return self.onPing(ping);
},
Strophe.NS.PING,
"iq",
"get"
);
self.connection.send($pres().tree());
break;
case Strophe.Status.ATTACHED:
this.logger.info(
`EjabService [Connection] Strophe is Attached with status ${status}`);
break;
case Strophe.Status.DISCONNECTED:
this.logger.info(
`EjabService [Connection] Strophe is Disconnected with status ${status}`);
break;
case Strophe.Status.AUTHFAIL:
this.logger.info(
`EjabService [Connection] Strophe is Authentication failed with status ${status}`);
break;
case Strophe.Status.CONNECTING:
this.logger.info(
`EjabService [Connection] Strophe is Connecting with status ${status}`);
break;
case Strophe.Status.DISCONNECTING:
this.logger.info(
`EjabService [Connection] Strophe is Disconnecting with status ${status}`);
break;
case Strophe.Status.AUTHENTICATING:
this.logger.info(
`EjabService [Connection] Strophe is Authenticating with status ${status}`);
break;
case Strophe.Status.ERROR:
case Strophe.Status.CONNFAIL:
this.logger.info(
`EjabService [Connection] Failed with status ${status}` );
break;
default:
this.logger.info(
`EjabService [Connection] Unknown status received: and status is ${status}`
);
break;
}
} catch (error) {
this.logger.info(`connection error ${error}`);
}
}
Related
When I try to connect to my nodejs server it is showing me this error-
connect_error: [{"cause":{"detailMessage":"Control frames must be final.","stackTrace":[],"suppressedExceptions":[]},"detailMessage":"websocket error","stackTrace":[],"suppressedExceptions":[]}]
I used flutter_socket_io for socket connection
My flutter code
socketIO = SocketIOManager().createSocketIO(
websocketUrl, '/', socketStatusCallback: (status) {
print("web socket -------------status");
print(status);
if (status.toString() == "connect") {
print("connected to server with websocket------------------------");
// socketIO.sendMessage("socket request", jsonEncode({"id": id}));
}
});
socketIO.init();
socketIO.connect().then((value){
print('socket connect');
});
I tried setup Binance websocket like this, what do I miss?
app.get("hello") { req -> EventLoopFuture<String> in
return WebSocket.connect(to: "wss://stream.binance.com:9443", headers: HTTPHeaders([("binance-api-key", "api-key"), ("binance-api-secret", "api-secret"), ("signature", "dcad576d5d0d9e25ee3fe427b0a50cdf9adec8ec528be05c9f1f7c684ee165f0")]), configuration: .init(), on: req.eventLoop, onUpgrade: { ws in
return
}).map({ _ in
return "done"
})
}
I reaise an error:
{
"error": true,
"reason": "invalidResponseStatus(HTTPResponseHead { version: HTTP/1.1, status: badRequest, headers: [(\"Date\", \"Sun, 12 Dec 2021 17:41:54 GMT\"), (\"Content-Type\", \"text/plain\"), (\"Content-Length\", \"20\"), (\"Connection\", \"keep-alive\")] })"
}
I have a super simple socket.io node server like below
// Socket!
io.on("connection", (socket) => {
console.log("a user connected");
socket.on("msg", (aaa) => {
console.log(aaa);
});
socket.on("fromServer", (_) => print(_));
console.log(socket.handshake.query)
});
And, here is my Flutter code to connect to the server
// Dart client
IO.Socket socket = IO.io(
'http://192.168.219.102:7199',
IO.OptionBuilder()
.setTransports(['polling'])
.disableAutoConnect()
.setQuery({"hee": 'asdf'})
.build());
socket.connect();
socket.onConnect((_) {
print(_);
});
On the network tab, I see two requests
101 HTTP 490ms
101 WS Pending
When I connect to the socket.io server from the other node.js server, I see the console.log of a user connected on the terminal. However, I see nothing from Flutter.
What can I do to receive the socket message on the server and connect the device.
I have two server. server1 will recieve upload request from user and pipe that request to server2 to upload file to server2. Here is my code for server1
upload: function (req, res) {
console.log(req.headers);
console.log(req.body);
req.pipe(request.post('http://localhost:1337/file/upload')).pipe(res);
}
and here is code for server2:
upload: function (req, res) {
console.log(req.allParams());
console.log(req.file());
console.log(req.headers);
if (req.file("mot")) {
req.file('mot').upload({
dirname: require('path').resolve(sails.config.appPath, 'data')
}, function (err, data) {
if (err) {
console.log(err);
return res.json({
failed: true
});
} else {
console.log("file uploaded");
return res.ok();
}
}
)
}else{
}
}
when is use postman to send upload request directly to server2 it work. but when i send request to server1 i got this error on server2:
{ Error: ETIMEOUT: An Upstream (`mot`) timed out waiting for file(s). No files were sent after waiting 10000ms.
at Timeout.<anonymous> (/media/thanhtv/Data/bitbucket/nodejs/test/node_modules/skipper/standalone/Upstream/Upstream.js:62:15)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)
code: 'ETIMEOUT',
message:
'ETIMEOUT: An Upstream (`mot`) timed out waiting for file(s). No files were sent after waiting 10000ms.' }
please help me out. i'm using sails.
I can access separately but I cannot connect both of theese services.(AWS Elasticache(Redis) and AWS EC2 (MongoDB)). I tried theese: EC2, Elasticache and Lambda in same security group in AWS VPC. Also tried EC2 and Elasticache in different security group AWS VPC and lambda has these security groups. But didn't change anything. I used serverless framework 1.0. These connections in localhost redis and EC2(MongoDB) worked together succesfully. When I was writing to console serverless deploy, these operations did'nt work. Postman error is: 502 Bad Gateway.
{
"message": "Internal server error"
}
Here it is(I can connect to redis succesfully):
var client = redis.createClient(config.cache.connection.port, config.cache.connection.endpoint);
client.on("error", function (err) {
if(err){
console.log("Error: Redis connection was failed");
}else{
console.log("Success: Redis connection was established");
}
});
client.set("FEED10", "feed", redis.print);
client.get("FEED10", function(err, data){
if(err){
console.log("Error: ", err);
}
console.log("DATA: ", data);
client.quit();
});
Here it is(ı can connect to mongodb succesfully)
var options = {
user: config.database.connection.user,
pass: config.database.connection.password,
promiseLibrary: require('bluebird')
}
mongoose.connect(config.database.connection.endpoint, options, function(error) {
// Check error in initial connection. There is no 2nd param to the callback.
if(error){
console.log("Error: MongoDB connection was failed");
}
else{
console.log("Success: MongoDB connection was established");
}
});
Here it is(i can connect MongoDB but con not redis). Any ideas?
var options = {
user: config.database.connection.user,
pass: config.database.connection.password,
promiseLibrary: require('bluebird')
}
mongoose.connect(config.database.connection.endpoint, options, function(error) {
// Check error in initial connection. There is no 2nd param to the callback.
if(error){
console.log("Error: MongoDB connection was failed");
}
else{
console.log("Success: MongoDB connection was established");
}
});
var client = redis.createClient(config.cache.connection.port, config.cache.connection.endpoint);
client.on("error", function (err) {
if(err){
console.log("Error: Redis connection was failed");
}else{
console.log("Success: Redis connection was established");
}
});
client.set("FEED10", "feed", redis.print);
client.get("FEED10", function(err, data){
if(err){
console.log("Error: ", err);
}
console.log("DATA: ", data);
client.quit();
});